mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
Changed all C# control flow block statements to include space between keyword and open paren
This commit is contained in:
@ -28,7 +28,7 @@ namespace Bit.Core
|
||||
|
||||
public void Build(HttpContext httpContext, GlobalSettings globalSettings)
|
||||
{
|
||||
if(_builtHttpContext)
|
||||
if (_builtHttpContext)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -37,12 +37,12 @@ namespace Bit.Core
|
||||
HttpContext = httpContext;
|
||||
Build(httpContext.User, globalSettings);
|
||||
|
||||
if(DeviceIdentifier == null && httpContext.Request.Headers.ContainsKey("Device-Identifier"))
|
||||
if (DeviceIdentifier == null && httpContext.Request.Headers.ContainsKey("Device-Identifier"))
|
||||
{
|
||||
DeviceIdentifier = httpContext.Request.Headers["Device-Identifier"];
|
||||
}
|
||||
|
||||
if(httpContext.Request.Headers.ContainsKey("Device-Type") &&
|
||||
if (httpContext.Request.Headers.ContainsKey("Device-Type") &&
|
||||
Enum.TryParse(httpContext.Request.Headers["Device-Type"].ToString(), out DeviceType dType))
|
||||
{
|
||||
DeviceType = dType;
|
||||
@ -51,14 +51,14 @@ namespace Bit.Core
|
||||
|
||||
public void Build(ClaimsPrincipal user, GlobalSettings globalSettings)
|
||||
{
|
||||
if(_builtClaimsPrincipal)
|
||||
if (_builtClaimsPrincipal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_builtClaimsPrincipal = true;
|
||||
IpAddress = HttpContext.GetIpAddress(globalSettings);
|
||||
if(user == null || !user.Claims.Any())
|
||||
if (user == null || !user.Claims.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -66,7 +66,7 @@ namespace Bit.Core
|
||||
var claimsDict = user.Claims.GroupBy(c => c.Type).ToDictionary(c => c.Key, c => c.Select(v => v));
|
||||
|
||||
var subject = GetClaimValue(claimsDict, "sub");
|
||||
if(Guid.TryParse(subject, out var subIdGuid))
|
||||
if (Guid.TryParse(subject, out var subIdGuid))
|
||||
{
|
||||
UserId = subIdGuid;
|
||||
}
|
||||
@ -74,18 +74,18 @@ namespace Bit.Core
|
||||
var clientId = GetClaimValue(claimsDict, "client_id");
|
||||
var clientSubject = GetClaimValue(claimsDict, "client_sub");
|
||||
var orgApi = false;
|
||||
if(clientSubject != null)
|
||||
if (clientSubject != null)
|
||||
{
|
||||
if(clientId?.StartsWith("installation.") ?? false)
|
||||
if (clientId?.StartsWith("installation.") ?? false)
|
||||
{
|
||||
if(Guid.TryParse(clientSubject, out var idGuid))
|
||||
if (Guid.TryParse(clientSubject, out var idGuid))
|
||||
{
|
||||
InstallationId = idGuid;
|
||||
}
|
||||
}
|
||||
else if(clientId?.StartsWith("organization.") ?? false)
|
||||
else if (clientId?.StartsWith("organization.") ?? false)
|
||||
{
|
||||
if(Guid.TryParse(clientSubject, out var idGuid))
|
||||
if (Guid.TryParse(clientSubject, out var idGuid))
|
||||
{
|
||||
OrganizationId = idGuid;
|
||||
orgApi = true;
|
||||
@ -96,7 +96,7 @@ namespace Bit.Core
|
||||
DeviceIdentifier = GetClaimValue(claimsDict, "device");
|
||||
|
||||
Organizations = new List<CurrentContentOrganization>();
|
||||
if(claimsDict.ContainsKey("orgowner"))
|
||||
if (claimsDict.ContainsKey("orgowner"))
|
||||
{
|
||||
Organizations.AddRange(claimsDict["orgowner"].Select(c =>
|
||||
new CurrentContentOrganization
|
||||
@ -105,7 +105,7 @@ namespace Bit.Core
|
||||
Type = OrganizationUserType.Owner
|
||||
}));
|
||||
}
|
||||
else if(orgApi && OrganizationId.HasValue)
|
||||
else if (orgApi && OrganizationId.HasValue)
|
||||
{
|
||||
Organizations.Add(new CurrentContentOrganization
|
||||
{
|
||||
@ -114,7 +114,7 @@ namespace Bit.Core
|
||||
});
|
||||
}
|
||||
|
||||
if(claimsDict.ContainsKey("orgadmin"))
|
||||
if (claimsDict.ContainsKey("orgadmin"))
|
||||
{
|
||||
Organizations.AddRange(claimsDict["orgadmin"].Select(c =>
|
||||
new CurrentContentOrganization
|
||||
@ -124,7 +124,7 @@ namespace Bit.Core
|
||||
}));
|
||||
}
|
||||
|
||||
if(claimsDict.ContainsKey("orguser"))
|
||||
if (claimsDict.ContainsKey("orguser"))
|
||||
{
|
||||
Organizations.AddRange(claimsDict["orguser"].Select(c =>
|
||||
new CurrentContentOrganization
|
||||
@ -134,7 +134,7 @@ namespace Bit.Core
|
||||
}));
|
||||
}
|
||||
|
||||
if(claimsDict.ContainsKey("orgmanager"))
|
||||
if (claimsDict.ContainsKey("orgmanager"))
|
||||
{
|
||||
Organizations.AddRange(claimsDict["orgmanager"].Select(c =>
|
||||
new CurrentContentOrganization
|
||||
@ -171,7 +171,7 @@ namespace Bit.Core
|
||||
public async Task<ICollection<CurrentContentOrganization>> OrganizationMembershipAsync(
|
||||
IOrganizationUserRepository organizationUserRepository, Guid userId)
|
||||
{
|
||||
if(Organizations == null)
|
||||
if (Organizations == null)
|
||||
{
|
||||
var userOrgs = await organizationUserRepository.GetManyByUserAsync(userId);
|
||||
Organizations = userOrgs.Where(ou => ou.Status == OrganizationUserStatusType.Confirmed)
|
||||
@ -182,7 +182,7 @@ namespace Bit.Core
|
||||
|
||||
private string GetClaimValue(Dictionary<string, IEnumerable<Claim>> claims, string type)
|
||||
{
|
||||
if(!claims.ContainsKey(type))
|
||||
if (!claims.ContainsKey(type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Exceptions
|
||||
public BadRequestException(ModelStateDictionary modelState)
|
||||
: base("The model state is invalid.")
|
||||
{
|
||||
if(modelState.IsValid || modelState.ErrorCount == 0)
|
||||
if (modelState.IsValid || modelState.ErrorCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Bit.Core.HostedServices
|
||||
EnableDeadLetteringOnMessageExpiration = true,
|
||||
}, new RuleDescription("default", new SqlFilter($"sys.Label != '{_subName}'")));
|
||||
}
|
||||
catch(MessagingEntityAlreadyExistsException) { }
|
||||
catch (MessagingEntityAlreadyExistsException) { }
|
||||
_subscriptionClient.RegisterMessageHandler(ProcessMessageAsync,
|
||||
new MessageHandlerOptions(ExceptionReceivedHandlerAsync)
|
||||
{
|
||||
@ -74,14 +74,14 @@ namespace Bit.Core.HostedServices
|
||||
|
||||
private async Task ProcessMessageAsync(Message message, CancellationToken cancellationToken)
|
||||
{
|
||||
if(message.Label != _subName && _applicationCacheService != null)
|
||||
if (message.Label != _subName && _applicationCacheService != null)
|
||||
{
|
||||
switch((ApplicationCacheMessageType)message.UserProperties["type"])
|
||||
switch ((ApplicationCacheMessageType)message.UserProperties["type"])
|
||||
{
|
||||
case ApplicationCacheMessageType.UpsertOrganizationAbility:
|
||||
var upsertedOrgId = (Guid)message.UserProperties["id"];
|
||||
var upsertedOrg = await _organizationRepository.GetByIdAsync(upsertedOrgId);
|
||||
if(upsertedOrg != null)
|
||||
if (upsertedOrg != null)
|
||||
{
|
||||
await _applicationCacheService.BaseUpsertOrganizationAbilityAsync(upsertedOrg);
|
||||
}
|
||||
@ -94,7 +94,7 @@ namespace Bit.Core.HostedServices
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!cancellationToken.IsCancellationRequested)
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||
{
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
|
||||
if(string.IsNullOrWhiteSpace((string)provider?.MetaData["Key"]))
|
||||
if (string.IsNullOrWhiteSpace((string)provider?.MetaData["Key"]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.TryAddScoped<SignInManager<TUser>>();
|
||||
services.TryAddScoped<RoleManager<TRole>>();
|
||||
|
||||
if(setupAction != null)
|
||||
if (setupAction != null)
|
||||
{
|
||||
services.Configure(setupAction);
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -43,13 +43,13 @@ namespace Bit.Core.Identity
|
||||
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -62,13 +62,13 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||
{
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace Bit.Core.Identity
|
||||
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||
{
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -57,11 +57,11 @@ namespace Bit.Core.Identity
|
||||
var emailParts = email.Split('@');
|
||||
|
||||
string shownPart = null;
|
||||
if(emailParts[0].Length > 2 && emailParts[0].Length <= 4)
|
||||
if (emailParts[0].Length > 2 && emailParts[0].Length <= 4)
|
||||
{
|
||||
shownPart = emailParts[0].Substring(0, 1);
|
||||
}
|
||||
else if(emailParts[0].Length > 4)
|
||||
else if (emailParts[0].Length > 4)
|
||||
{
|
||||
shownPart = emailParts[0].Substring(0, 2);
|
||||
}
|
||||
@ -71,7 +71,7 @@ namespace Bit.Core.Identity
|
||||
}
|
||||
|
||||
string redactedPart = null;
|
||||
if(emailParts[0].Length > 4)
|
||||
if (emailParts[0].Length > 4)
|
||||
{
|
||||
redactedPart = new string('*', emailParts[0].Length - 2);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Identity
|
||||
|
||||
public Task<bool> CanGenerateTwoFactorTokenAsync(Organization organization)
|
||||
{
|
||||
if(organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
if (organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
@ -32,13 +32,13 @@ namespace Bit.Core.Identity
|
||||
|
||||
public Task<string> GenerateAsync(Organization organization, User user)
|
||||
{
|
||||
if(organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
if (organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
var provider = organization.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
@ -50,13 +50,13 @@ namespace Bit.Core.Identity
|
||||
|
||||
public Task<bool> ValidateAsync(string token, Organization organization, User user)
|
||||
{
|
||||
if(organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
if (organization == null || !organization.Enabled || !organization.Use2fa)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
var provider = organization.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace Bit.Core.Identity
|
||||
public async Task<SignInResult> PasswordlessSignInAsync(string email, string returnUrl)
|
||||
{
|
||||
var user = await UserManager.FindByEmailAsync(email);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
return SignInResult.Failed;
|
||||
}
|
||||
@ -45,7 +45,7 @@ namespace Bit.Core.Identity
|
||||
|
||||
public async Task<SignInResult> PasswordlessSignInAsync(TUser user, string token, bool isPersistent)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace Bit.Core.Identity
|
||||
public async Task<SignInResult> PasswordlessSignInAsync(string email, string token, bool isPersistent)
|
||||
{
|
||||
var user = await UserManager.FindByEmailAsync(email);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
return SignInResult.Failed;
|
||||
}
|
||||
@ -68,18 +68,18 @@ namespace Bit.Core.Identity
|
||||
|
||||
public virtual async Task<SignInResult> CheckPasswordlessSignInAsync(TUser user, string token)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var error = await PreSignInCheck(user);
|
||||
if(error != null)
|
||||
if (error != null)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if(await UserManager.VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider,
|
||||
if (await UserManager.VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider,
|
||||
PasswordlessSignInPurpose, token))
|
||||
{
|
||||
return SignInResult.Success;
|
||||
|
@ -30,7 +30,7 @@ namespace Bit.Core.Identity
|
||||
public override async Task<IdentityUser> FindByIdAsync(string userId,
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if(!Guid.TryParse(userId, out var userIdGuid))
|
||||
if (!Guid.TryParse(userId, out var userIdGuid))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -20,17 +20,17 @@ namespace Bit.Core.Identity
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var usersCsv = _configuration["adminSettings:admins"];
|
||||
if(!CoreHelpers.SettingHasValue(usersCsv))
|
||||
if (!CoreHelpers.SettingHasValue(usersCsv))
|
||||
{
|
||||
return Task.FromResult<IdentityUser>(null);
|
||||
}
|
||||
|
||||
var users = usersCsv.ToLowerInvariant().Split(',');
|
||||
var usersDict = new Dictionary<string, string>();
|
||||
foreach(var u in users)
|
||||
foreach (var u in users)
|
||||
{
|
||||
var parts = u.Split(':');
|
||||
if(parts.Length == 2)
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
var email = parts[0].Trim();
|
||||
var stamp = parts[1].Trim();
|
||||
@ -44,7 +44,7 @@ namespace Bit.Core.Identity
|
||||
}
|
||||
|
||||
var userStamp = usersDict.ContainsKey(normalizedEmail) ? usersDict[normalizedEmail] : null;
|
||||
if(userStamp == null)
|
||||
if (userStamp == null)
|
||||
{
|
||||
return Task.FromResult<IdentityUser>(null);
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.U2f);
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -53,14 +53,14 @@ namespace Bit.Core.Identity
|
||||
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.U2f);
|
||||
var keys = LoadKeys(provider);
|
||||
if(keys.Count == 0)
|
||||
if (keys.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -73,7 +73,7 @@ namespace Bit.Core.Identity
|
||||
var appId = Utilities.CoreHelpers.U2fAppIdUrl(_globalSettings);
|
||||
var oldChallenges = new List<object>();
|
||||
var challengeKeys = new List<object>();
|
||||
foreach(var key in keys)
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var registration = new DeviceRegistration(key.Item2.KeyHandleBytes, key.Item2.PublicKeyBytes,
|
||||
key.Item2.CertificateBytes, key.Item2.Counter);
|
||||
@ -115,7 +115,7 @@ namespace Bit.Core.Identity
|
||||
});
|
||||
return $"{token}|{oldToken}";
|
||||
}
|
||||
catch(U2fException)
|
||||
catch (U2fException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -124,14 +124,14 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)) || string.IsNullOrWhiteSpace(token))
|
||||
if (!(await userService.CanAccessPremium(user)) || string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.U2f);
|
||||
var keys = LoadKeys(provider);
|
||||
if(keys.Count == 0)
|
||||
if (keys.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -139,13 +139,13 @@ namespace Bit.Core.Identity
|
||||
var authenticateResponse = BaseModel.FromJson<AuthenticateResponse>(token);
|
||||
var key = keys.FirstOrDefault(f => f.Item2.KeyHandle == authenticateResponse.KeyHandle);
|
||||
|
||||
if(key == null)
|
||||
if (key == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var challenges = await _u2fRepository.GetManyByUserIdAsync(user.Id);
|
||||
if(challenges.Count == 0)
|
||||
if (challenges.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -153,7 +153,7 @@ namespace Bit.Core.Identity
|
||||
// User will have a authentication request for each device they have registered so get the one that matches
|
||||
// the device key handle
|
||||
var challenge = challenges.FirstOrDefault(c => c.KeyHandle == authenticateResponse.KeyHandle);
|
||||
if(challenge == null)
|
||||
if (challenge == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -166,7 +166,7 @@ namespace Bit.Core.Identity
|
||||
var auth = new StartedAuthentication(challenge.Challenge, challenge.AppId, challenge.KeyHandle);
|
||||
U2fLib.FinishAuthentication(auth, authenticateResponse, registration);
|
||||
}
|
||||
catch(U2fException)
|
||||
catch (U2fException)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
@ -174,7 +174,7 @@ namespace Bit.Core.Identity
|
||||
// Update database
|
||||
await _u2fRepository.DeleteManyByUserIdAsync(user.Id);
|
||||
key.Item2.Counter = registration.Counter;
|
||||
if(key.Item2.Counter > 0)
|
||||
if (key.Item2.Counter > 0)
|
||||
{
|
||||
key.Item2.Compromised = registration.IsCompromised;
|
||||
}
|
||||
@ -195,19 +195,19 @@ namespace Bit.Core.Identity
|
||||
private List<Tuple<string, TwoFactorProvider.U2fMetaData>> LoadKeys(TwoFactorProvider provider)
|
||||
{
|
||||
var keys = new List<Tuple<string, TwoFactorProvider.U2fMetaData>>();
|
||||
if(!HasProperMetaData(provider))
|
||||
if (!HasProperMetaData(provider))
|
||||
{
|
||||
return keys;
|
||||
}
|
||||
|
||||
// Support up to 5 keys
|
||||
for(var i = 1; i <= 5; i++)
|
||||
for (var i = 1; i <= 5; i++)
|
||||
{
|
||||
var keyName = $"Key{i}";
|
||||
if(provider.MetaData.ContainsKey(keyName))
|
||||
if (provider.MetaData.ContainsKey(keyName))
|
||||
{
|
||||
var key = new TwoFactorProvider.U2fMetaData((dynamic)provider.MetaData[keyName]);
|
||||
if(!key?.Compromised ?? false)
|
||||
if (!key?.Compromised ?? false)
|
||||
{
|
||||
keys.Add(new Tuple<string, TwoFactorProvider.U2fMetaData>(keyName, key));
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace Bit.Core.Identity
|
||||
|
||||
public async Task<User> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if(_currentContext?.User != null && _currentContext.User.Email == normalizedEmail)
|
||||
if (_currentContext?.User != null && _currentContext.User.Email == normalizedEmail)
|
||||
{
|
||||
return _currentContext.User;
|
||||
}
|
||||
@ -57,14 +57,14 @@ namespace Bit.Core.Identity
|
||||
|
||||
public async Task<User> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if(_currentContext?.User != null &&
|
||||
if (_currentContext?.User != null &&
|
||||
string.Equals(_currentContext.User.Id.ToString(), userId, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return _currentContext.User;
|
||||
}
|
||||
|
||||
Guid userIdGuid;
|
||||
if(!Guid.TryParse(userId, out userIdGuid))
|
||||
if (!Guid.TryParse(userId, out userIdGuid))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
|
||||
if(!provider?.MetaData.Values.Any(v => !string.IsNullOrWhiteSpace((string)v)) ?? true)
|
||||
if (!provider?.MetaData.Values.Any(v => !string.IsNullOrWhiteSpace((string)v)) ?? true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -48,12 +48,12 @@ namespace Bit.Core.Identity
|
||||
public async Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
|
||||
{
|
||||
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||
if(!(await userService.CanAccessPremium(user)))
|
||||
if (!(await userService.CanAccessPremium(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(token) || token.Length < 32 || token.Length > 48)
|
||||
if (string.IsNullOrWhiteSpace(token) || token.Length < 32 || token.Length > 48)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -61,13 +61,13 @@ namespace Bit.Core.Identity
|
||||
var id = token.Substring(0, 12);
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
|
||||
if(!provider.MetaData.ContainsValue(id))
|
||||
if (!provider.MetaData.ContainsValue(id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key);
|
||||
if(_globalSettings.Yubico.ValidationUrls != null && _globalSettings.Yubico.ValidationUrls.Length > 0)
|
||||
if (_globalSettings.Yubico.ValidationUrls != null && _globalSettings.Yubico.ValidationUrls.Length > 0)
|
||||
{
|
||||
client.SetUrls(_globalSettings.Yubico.ValidationUrls);
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ namespace Bit.Core.IdentityServer
|
||||
|
||||
public async Task<Client> FindClientByIdAsync(string clientId)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted && clientId.StartsWith("installation."))
|
||||
if (!_globalSettings.SelfHosted && clientId.StartsWith("installation."))
|
||||
{
|
||||
var idParts = clientId.Split('.');
|
||||
if(idParts.Length > 1 && Guid.TryParse(idParts[1], out Guid id))
|
||||
if (idParts.Length > 1 && Guid.TryParse(idParts[1], out Guid id))
|
||||
{
|
||||
var installation = await _installationRepository.GetByIdAsync(id);
|
||||
if(installation != null)
|
||||
if (installation != null)
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
@ -52,14 +52,14 @@ namespace Bit.Core.IdentityServer
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(_globalSettings.SelfHosted && clientId.StartsWith("internal.") &&
|
||||
else if (_globalSettings.SelfHosted && clientId.StartsWith("internal.") &&
|
||||
CoreHelpers.SettingHasValue(_globalSettings.InternalIdentityKey))
|
||||
{
|
||||
var idParts = clientId.Split('.');
|
||||
if(idParts.Length > 1)
|
||||
if (idParts.Length > 1)
|
||||
{
|
||||
var id = idParts[1];
|
||||
if(!string.IsNullOrWhiteSpace(id))
|
||||
if (!string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
@ -75,13 +75,13 @@ namespace Bit.Core.IdentityServer
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(clientId.StartsWith("organization."))
|
||||
else if (clientId.StartsWith("organization."))
|
||||
{
|
||||
var idParts = clientId.Split('.');
|
||||
if(idParts.Length > 1 && Guid.TryParse(idParts[1], out var id))
|
||||
if (idParts.Length > 1 && Guid.TryParse(idParts[1], out var id))
|
||||
{
|
||||
var org = await _organizationRepository.GetByIdAsync(id);
|
||||
if(org != null)
|
||||
if (org != null)
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace Bit.Core.IdentityServer
|
||||
public async Task<PersistedGrant> GetAsync(string key)
|
||||
{
|
||||
var grant = await _grantRepository.GetByKeyAsync(key);
|
||||
if(grant == null)
|
||||
if (grant == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace Bit.Core.IdentityServer
|
||||
var newClaims = new List<Claim>();
|
||||
|
||||
var user = await _userService.GetUserByPrincipalAsync(context.Subject);
|
||||
if(user != null)
|
||||
if (user != null)
|
||||
{
|
||||
var isPremium = await _licensingService.ValidateUserPremiumAsync(user);
|
||||
newClaims.AddRange(new List<Claim>
|
||||
@ -50,39 +50,39 @@ namespace Bit.Core.IdentityServer
|
||||
new Claim("sstamp", user.SecurityStamp)
|
||||
});
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(user.Name))
|
||||
if (!string.IsNullOrWhiteSpace(user.Name))
|
||||
{
|
||||
newClaims.Add(new Claim(JwtClaimTypes.Name, user.Name));
|
||||
}
|
||||
|
||||
// Orgs that this user belongs to
|
||||
var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, user.Id);
|
||||
if(orgs.Any())
|
||||
if (orgs.Any())
|
||||
{
|
||||
foreach(var group in orgs.GroupBy(o => o.Type))
|
||||
foreach (var group in orgs.GroupBy(o => o.Type))
|
||||
{
|
||||
switch(group.Key)
|
||||
switch (group.Key)
|
||||
{
|
||||
case Enums.OrganizationUserType.Owner:
|
||||
foreach(var org in group)
|
||||
foreach (var org in group)
|
||||
{
|
||||
newClaims.Add(new Claim("orgowner", org.Id.ToString()));
|
||||
}
|
||||
break;
|
||||
case Enums.OrganizationUserType.Admin:
|
||||
foreach(var org in group)
|
||||
foreach (var org in group)
|
||||
{
|
||||
newClaims.Add(new Claim("orgadmin", org.Id.ToString()));
|
||||
}
|
||||
break;
|
||||
case Enums.OrganizationUserType.Manager:
|
||||
foreach(var org in group)
|
||||
foreach (var org in group)
|
||||
{
|
||||
newClaims.Add(new Claim("orgmanager", org.Id.ToString()));
|
||||
}
|
||||
break;
|
||||
case Enums.OrganizationUserType.User:
|
||||
foreach(var org in group)
|
||||
foreach (var org in group)
|
||||
{
|
||||
newClaims.Add(new Claim("orguser", org.Id.ToString()));
|
||||
}
|
||||
@ -100,7 +100,7 @@ namespace Bit.Core.IdentityServer
|
||||
.ToList();
|
||||
|
||||
newClaims.AddRange(existingClaimsToKeep);
|
||||
if(newClaims.Any())
|
||||
if (newClaims.Any())
|
||||
{
|
||||
context.AddRequestedClaims(newClaims);
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace Bit.Core.IdentityServer
|
||||
var securityTokenClaim = context.Subject?.Claims.FirstOrDefault(c => c.Type == "sstamp");
|
||||
var user = await _userService.GetUserByPrincipalAsync(context.Subject);
|
||||
|
||||
if(user != null && securityTokenClaim != null)
|
||||
if (user != null && securityTokenClaim != null)
|
||||
{
|
||||
context.IsActive = string.Equals(user.SecurityStamp, securityTokenClaim.Value,
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
|
@ -75,24 +75,24 @@ namespace Bit.Core.IdentityServer
|
||||
var twoFactorRequest = !string.IsNullOrWhiteSpace(twoFactorToken) &&
|
||||
!string.IsNullOrWhiteSpace(twoFactorProvider);
|
||||
|
||||
if(string.IsNullOrWhiteSpace(context.UserName))
|
||||
if (string.IsNullOrWhiteSpace(context.UserName))
|
||||
{
|
||||
await BuildErrorResultAsync(false, context, null);
|
||||
return;
|
||||
}
|
||||
|
||||
var user = await _userManager.FindByEmailAsync(context.UserName.ToLowerInvariant());
|
||||
if(user == null || !await _userService.CheckPasswordAsync(user, context.Password))
|
||||
if (user == null || !await _userService.CheckPasswordAsync(user, context.Password))
|
||||
{
|
||||
await BuildErrorResultAsync(false, context, user);
|
||||
return;
|
||||
}
|
||||
|
||||
var twoFactorRequirement = await RequiresTwoFactorAsync(user);
|
||||
if(twoFactorRequirement.Item1)
|
||||
if (twoFactorRequirement.Item1)
|
||||
{
|
||||
var twoFactorProviderType = TwoFactorProviderType.Authenticator; // Just defaulting it
|
||||
if(!twoFactorRequest || !Enum.TryParse(twoFactorProvider, out twoFactorProviderType))
|
||||
if (!twoFactorRequest || !Enum.TryParse(twoFactorProvider, out twoFactorProviderType))
|
||||
{
|
||||
await BuildTwoFactorResultAsync(user, twoFactorRequirement.Item2, context);
|
||||
return;
|
||||
@ -100,12 +100,12 @@ namespace Bit.Core.IdentityServer
|
||||
|
||||
var verified = await VerifyTwoFactor(user, twoFactorRequirement.Item2,
|
||||
twoFactorProviderType, twoFactorToken);
|
||||
if(!verified && twoFactorProviderType != TwoFactorProviderType.Remember)
|
||||
if (!verified && twoFactorProviderType != TwoFactorProviderType.Remember)
|
||||
{
|
||||
await BuildErrorResultAsync(true, context, user);
|
||||
return;
|
||||
}
|
||||
else if(!verified && twoFactorProviderType == TwoFactorProviderType.Remember)
|
||||
else if (!verified && twoFactorProviderType == TwoFactorProviderType.Remember)
|
||||
{
|
||||
await Task.Delay(2000); // Delay for brute force.
|
||||
await BuildTwoFactorResultAsync(user, twoFactorRequirement.Item2, context);
|
||||
@ -131,23 +131,23 @@ namespace Bit.Core.IdentityServer
|
||||
|
||||
var claims = new List<Claim>();
|
||||
|
||||
if(device != null)
|
||||
if (device != null)
|
||||
{
|
||||
claims.Add(new Claim("device", device.Identifier));
|
||||
}
|
||||
|
||||
var customResponse = new Dictionary<string, object>();
|
||||
if(!string.IsNullOrWhiteSpace(user.PrivateKey))
|
||||
if (!string.IsNullOrWhiteSpace(user.PrivateKey))
|
||||
{
|
||||
customResponse.Add("PrivateKey", user.PrivateKey);
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(user.Key))
|
||||
if (!string.IsNullOrWhiteSpace(user.Key))
|
||||
{
|
||||
customResponse.Add("Key", user.Key);
|
||||
}
|
||||
|
||||
if(sendRememberToken)
|
||||
if (sendRememberToken)
|
||||
{
|
||||
var token = await _userManager.GenerateTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(TwoFactorProviderType.Remember));
|
||||
@ -167,30 +167,30 @@ namespace Bit.Core.IdentityServer
|
||||
var providers = new Dictionary<byte, Dictionary<string, object>>();
|
||||
|
||||
var enabledProviders = new List<KeyValuePair<TwoFactorProviderType, TwoFactorProvider>>();
|
||||
if(organization?.GetTwoFactorProviders() != null)
|
||||
if (organization?.GetTwoFactorProviders() != null)
|
||||
{
|
||||
enabledProviders.AddRange(organization.GetTwoFactorProviders().Where(
|
||||
p => organization.TwoFactorProviderIsEnabled(p.Key)));
|
||||
}
|
||||
|
||||
if(user.GetTwoFactorProviders() != null)
|
||||
if (user.GetTwoFactorProviders() != null)
|
||||
{
|
||||
foreach(var p in user.GetTwoFactorProviders())
|
||||
foreach (var p in user.GetTwoFactorProviders())
|
||||
{
|
||||
if(await _userService.TwoFactorProviderIsEnabledAsync(p.Key, user))
|
||||
if (await _userService.TwoFactorProviderIsEnabledAsync(p.Key, user))
|
||||
{
|
||||
enabledProviders.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!enabledProviders.Any())
|
||||
if (!enabledProviders.Any())
|
||||
{
|
||||
await BuildErrorResultAsync(false, context, user);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var provider in enabledProviders)
|
||||
foreach (var provider in enabledProviders)
|
||||
{
|
||||
providerKeys.Add((byte)provider.Key);
|
||||
var infoDict = await BuildTwoFactorParams(organization, user, provider.Key, provider.Value);
|
||||
@ -204,7 +204,7 @@ namespace Bit.Core.IdentityServer
|
||||
{ "TwoFactorProviders2", providers }
|
||||
});
|
||||
|
||||
if(enabledProviders.Count() == 1 && enabledProviders.First().Key == TwoFactorProviderType.Email)
|
||||
if (enabledProviders.Count() == 1 && enabledProviders.First().Key == TwoFactorProviderType.Email)
|
||||
{
|
||||
// Send email now if this is their only 2FA method
|
||||
await _userService.SendTwoFactorEmailAsync(user);
|
||||
@ -214,13 +214,13 @@ namespace Bit.Core.IdentityServer
|
||||
private async Task BuildErrorResultAsync(bool twoFactorRequest,
|
||||
ResourceOwnerPasswordValidationContext context, User user)
|
||||
{
|
||||
if(user != null)
|
||||
if (user != null)
|
||||
{
|
||||
await _eventService.LogUserEventAsync(user.Id,
|
||||
twoFactorRequest ? EventType.User_FailedLogIn2fa : EventType.User_FailedLogIn);
|
||||
}
|
||||
|
||||
if(_globalSettings.SelfHosted)
|
||||
if (_globalSettings.SelfHosted)
|
||||
{
|
||||
_logger.LogWarning(Constants.BypassFiltersEventId,
|
||||
string.Format("Failed login attempt{0}{1}", twoFactorRequest ? ", 2FA invalid." : ".",
|
||||
@ -244,11 +244,11 @@ namespace Bit.Core.IdentityServer
|
||||
Organization firstEnabledOrg = null;
|
||||
var orgs = (await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, user.Id))
|
||||
.ToList();
|
||||
if(orgs.Any())
|
||||
if (orgs.Any())
|
||||
{
|
||||
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
|
||||
var twoFactorOrgs = orgs.Where(o => OrgUsing2fa(orgAbilities, o.Id));
|
||||
if(twoFactorOrgs.Any())
|
||||
if (twoFactorOrgs.Any())
|
||||
{
|
||||
var userOrgs = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
||||
firstEnabledOrg = userOrgs.FirstOrDefault(
|
||||
@ -272,7 +272,7 @@ namespace Bit.Core.IdentityServer
|
||||
var deviceName = context.Request.Raw["DeviceName"]?.ToString();
|
||||
var devicePushToken = context.Request.Raw["DevicePushToken"]?.ToString();
|
||||
|
||||
if(string.IsNullOrWhiteSpace(deviceIdentifier) || string.IsNullOrWhiteSpace(deviceType) ||
|
||||
if (string.IsNullOrWhiteSpace(deviceIdentifier) || string.IsNullOrWhiteSpace(deviceType) ||
|
||||
string.IsNullOrWhiteSpace(deviceName) || !Enum.TryParse(deviceType, out DeviceType type))
|
||||
{
|
||||
return null;
|
||||
@ -290,7 +290,7 @@ namespace Bit.Core.IdentityServer
|
||||
private async Task<bool> VerifyTwoFactor(User user, Organization organization, TwoFactorProviderType type,
|
||||
string token)
|
||||
{
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case TwoFactorProviderType.Authenticator:
|
||||
case TwoFactorProviderType.Email:
|
||||
@ -298,7 +298,7 @@ namespace Bit.Core.IdentityServer
|
||||
case TwoFactorProviderType.YubiKey:
|
||||
case TwoFactorProviderType.U2f:
|
||||
case TwoFactorProviderType.Remember:
|
||||
if(type != TwoFactorProviderType.Remember &&
|
||||
if (type != TwoFactorProviderType.Remember &&
|
||||
!(await _userService.TwoFactorProviderIsEnabledAsync(type, user)))
|
||||
{
|
||||
return false;
|
||||
@ -306,7 +306,7 @@ namespace Bit.Core.IdentityServer
|
||||
return await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(type), token);
|
||||
case TwoFactorProviderType.OrganizationDuo:
|
||||
if(!organization?.TwoFactorProviderIsEnabled(type) ?? true)
|
||||
if (!organization?.TwoFactorProviderIsEnabled(type) ?? true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -320,20 +320,20 @@ namespace Bit.Core.IdentityServer
|
||||
private async Task<Dictionary<string, object>> BuildTwoFactorParams(Organization organization, User user,
|
||||
TwoFactorProviderType type, TwoFactorProvider provider)
|
||||
{
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case TwoFactorProviderType.Duo:
|
||||
case TwoFactorProviderType.U2f:
|
||||
case TwoFactorProviderType.Email:
|
||||
case TwoFactorProviderType.YubiKey:
|
||||
if(!(await _userService.TwoFactorProviderIsEnabledAsync(type, user)))
|
||||
if (!(await _userService.TwoFactorProviderIsEnabledAsync(type, user)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var token = await _userManager.GenerateTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(type));
|
||||
if(type == TwoFactorProviderType.Duo)
|
||||
if (type == TwoFactorProviderType.Duo)
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
@ -341,7 +341,7 @@ namespace Bit.Core.IdentityServer
|
||||
["Signature"] = token
|
||||
};
|
||||
}
|
||||
else if(type == TwoFactorProviderType.U2f)
|
||||
else if (type == TwoFactorProviderType.U2f)
|
||||
{
|
||||
// TODO: Remove "Challenges" in a future update. Deprecated.
|
||||
var tokens = token?.Split('|');
|
||||
@ -351,14 +351,14 @@ namespace Bit.Core.IdentityServer
|
||||
["Challenges"] = tokens != null && tokens.Length > 1 ? tokens[1] : null
|
||||
};
|
||||
}
|
||||
else if(type == TwoFactorProviderType.Email)
|
||||
else if (type == TwoFactorProviderType.Email)
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
["Email"] = token
|
||||
};
|
||||
}
|
||||
else if(type == TwoFactorProviderType.YubiKey)
|
||||
else if (type == TwoFactorProviderType.YubiKey)
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
@ -367,7 +367,7 @@ namespace Bit.Core.IdentityServer
|
||||
}
|
||||
return null;
|
||||
case TwoFactorProviderType.OrganizationDuo:
|
||||
if(await _organizationDuoWebTokenProvider.CanGenerateTwoFactorTokenAsync(organization))
|
||||
if (await _organizationDuoWebTokenProvider.CanGenerateTwoFactorTokenAsync(organization))
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
@ -384,20 +384,20 @@ namespace Bit.Core.IdentityServer
|
||||
private async Task<Device> SaveDeviceAsync(User user, ResourceOwnerPasswordValidationContext context)
|
||||
{
|
||||
var device = GetDeviceFromRequest(context);
|
||||
if(device != null)
|
||||
if (device != null)
|
||||
{
|
||||
var existingDevice = await _deviceRepository.GetByIdentifierAsync(device.Identifier, user.Id);
|
||||
if(existingDevice == null)
|
||||
if (existingDevice == null)
|
||||
{
|
||||
device.UserId = user.Id;
|
||||
await _deviceService.SaveAsync(device);
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
if(now - user.CreationDate > TimeSpan.FromMinutes(10))
|
||||
if (now - user.CreationDate > TimeSpan.FromMinutes(10))
|
||||
{
|
||||
var deviceType = device.Type.GetType().GetMember(device.Type.ToString())
|
||||
.FirstOrDefault()?.GetCustomAttribute<DisplayAttribute>()?.GetName();
|
||||
if(!_globalSettings.DisableEmailNewDevice)
|
||||
if (!_globalSettings.DisableEmailNewDevice)
|
||||
{
|
||||
await _mailService.SendNewDeviceLoggedInEmail(user.Email, deviceType, now,
|
||||
_currentContext.IpAddress);
|
||||
|
@ -38,7 +38,7 @@ namespace Bit.Core.IdentityServer
|
||||
AccessTokenLifetime = 3600 * accessTokenLifetimeHours;
|
||||
AllowOfflineAccess = true;
|
||||
|
||||
if(scopes == null)
|
||||
if (scopes == null)
|
||||
{
|
||||
scopes = new string[] { "api" };
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ namespace Bit.Core.IdentityServer
|
||||
return (request) =>
|
||||
{
|
||||
var authorization = request.Headers[_authHeader].FirstOrDefault();
|
||||
if(string.IsNullOrWhiteSpace(authorization))
|
||||
if (string.IsNullOrWhiteSpace(authorization))
|
||||
{
|
||||
return request.Query[_queuryScheme].FirstOrDefault();
|
||||
}
|
||||
|
||||
if(authorization.StartsWith(_headerScheme, StringComparison.OrdinalIgnoreCase))
|
||||
if (authorization.StartsWith(_headerScheme, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return authorization.Substring(_headerScheme.Length).Trim();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace Bit.Core.Jobs
|
||||
{
|
||||
await ExecuteJobAsync(context);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(2, e, "Error performing {0}.", GetType().Name);
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ namespace Bit.Core.Jobs
|
||||
_scheduler.ListenerManager.AddJobListener(new JobListener(_listenerLogger),
|
||||
GroupMatcher<JobKey>.AnyGroup());
|
||||
await _scheduler.Start(cancellationToken);
|
||||
if(Jobs != null)
|
||||
if (Jobs != null)
|
||||
{
|
||||
foreach(var job in Jobs)
|
||||
foreach (var job in Jobs)
|
||||
{
|
||||
var builtJob = JobBuilder.Create(job.Item1).Build();
|
||||
await _scheduler.ScheduleJob(builtJob, job.Item2);
|
||||
|
@ -15,7 +15,7 @@ namespace Bit.Core.Models.Api
|
||||
public CipherLoginModel(CipherLoginData data)
|
||||
{
|
||||
Uris = data.Uris?.Select(u => new CipherLoginUriModel(u))?.ToList();
|
||||
if(!Uris?.Any() ?? true)
|
||||
if (!Uris?.Any() ?? true)
|
||||
{
|
||||
Uri = data.Uri;
|
||||
}
|
||||
@ -33,12 +33,12 @@ namespace Bit.Core.Models.Api
|
||||
get => Uris?.FirstOrDefault()?.Uri;
|
||||
set
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(value))
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(Uris == null)
|
||||
if (Uris == null)
|
||||
{
|
||||
Uris = new List<CipherLoginUriModel>();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
|
||||
public MemberBaseModel(OrganizationUser user)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -24,7 +24,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
|
||||
public MemberBaseModel(OrganizationUserUserDetails user)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -28,19 +28,19 @@ namespace Bit.Core.Models.Api.Public
|
||||
|
||||
public Tuple<DateTime, DateTime> ToDateRange()
|
||||
{
|
||||
if(!End.HasValue || !Start.HasValue)
|
||||
if (!End.HasValue || !Start.HasValue)
|
||||
{
|
||||
End = DateTime.UtcNow.Date.AddDays(1).AddMilliseconds(-1);
|
||||
Start = DateTime.UtcNow.Date.AddDays(-30);
|
||||
}
|
||||
else if(Start.Value > End.Value)
|
||||
else if (Start.Value > End.Value)
|
||||
{
|
||||
var newEnd = Start;
|
||||
Start = End;
|
||||
End = newEnd;
|
||||
}
|
||||
|
||||
if((End.Value - Start.Value) > TimeSpan.FromDays(367))
|
||||
if ((End.Value - Start.Value) > TimeSpan.FromDays(367))
|
||||
{
|
||||
throw new BadRequestException("Date range must be < 367 days.");
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ namespace Bit.Core.Models.Api.Public
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Email.Contains(" ") || Email.Contains("<"))
|
||||
if (Email.Contains(" ") || Email.Contains("<"))
|
||||
{
|
||||
yield return new ValidationResult($"Email is not valid.",
|
||||
new string[] { nameof(Email) });
|
||||
}
|
||||
else if(Email.Length > 50)
|
||||
else if (Email.Length > 50)
|
||||
{
|
||||
yield return new ValidationResult($"Email is longer than 50 characters.",
|
||||
new string[] { nameof(Email) });
|
||||
|
@ -7,7 +7,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public AssociationWithPermissionsResponseModel(SelectionReadOnly selection)
|
||||
{
|
||||
if(selection == null)
|
||||
if (selection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(selection));
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public CollectionResponseModel(Collection collection, IEnumerable<SelectionReadOnly> groups)
|
||||
{
|
||||
if(collection == null)
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(collection));
|
||||
}
|
||||
|
@ -20,17 +20,17 @@ namespace Bit.Core.Models.Api.Public
|
||||
var keys = modelState.Keys.ToList();
|
||||
var values = modelState.Values.ToList();
|
||||
|
||||
for(var i = 0; i < values.Count; i++)
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
{
|
||||
var value = values[i];
|
||||
if(keys.Count <= i)
|
||||
if (keys.Count <= i)
|
||||
{
|
||||
// Keys not available for some reason.
|
||||
break;
|
||||
}
|
||||
|
||||
var key = keys[i];
|
||||
if(value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
if (value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public EventResponseModel(IEvent ev)
|
||||
{
|
||||
if(ev == null)
|
||||
if (ev == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ev));
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public GroupResponseModel(Group group, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
if(group == null)
|
||||
if (group == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(group));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
public MemberResponseModel(OrganizationUser user, IEnumerable<SelectionReadOnly> collections)
|
||||
: base(user)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
IEnumerable<SelectionReadOnly> collections)
|
||||
: base(user)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public PolicyResponseModel(Policy policy)
|
||||
{
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(policy));
|
||||
}
|
||||
@ -21,7 +21,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
Id = policy.Id;
|
||||
Type = policy.Type;
|
||||
Enabled = policy.Enabled;
|
||||
if(!string.IsNullOrWhiteSpace(policy.Data))
|
||||
if (!string.IsNullOrWhiteSpace(policy.Data))
|
||||
{
|
||||
Data = JsonConvert.DeserializeObject<Dictionary<string, object>>(policy.Data);
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Kdf.HasValue && KdfIterations.HasValue)
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch(Kdf.Value)
|
||||
switch (Kdf.Value)
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if(KdfIterations.Value < 5000 || KdfIterations.Value > 2_000_000)
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 2_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 2000000.");
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
{
|
||||
existingUser.PublicKey = PublicKey;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
{
|
||||
existingUser.PrivateKey = EncryptedPrivateKey;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace Bit.Core.Models.Api
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
var creditType = PaymentMethodType.HasValue && PaymentMethodType.Value == Enums.PaymentMethodType.Credit;
|
||||
if(string.IsNullOrWhiteSpace(PaymentToken) && !creditType && License == null)
|
||||
if (string.IsNullOrWhiteSpace(PaymentToken) && !creditType && License == null)
|
||||
{
|
||||
yield return new ValidationResult("Payment token or license is required.");
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ namespace Bit.Core.Models.Api
|
||||
KdfIterations = KdfIterations.GetValueOrDefault(5000)
|
||||
};
|
||||
|
||||
if(Key != null)
|
||||
if (Key != null)
|
||||
{
|
||||
user.Key = Key;
|
||||
}
|
||||
|
||||
if(Keys != null)
|
||||
if (Keys != null)
|
||||
{
|
||||
Keys.ToUser(user);
|
||||
}
|
||||
@ -52,12 +52,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Kdf.HasValue && KdfIterations.HasValue)
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch(Kdf.Value)
|
||||
switch (Kdf.Value)
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if(KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 1000000.");
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(StorageGbAdjustment == 0)
|
||||
if (StorageGbAdjustment == 0)
|
||||
{
|
||||
yield return new ValidationResult("Storage adjustment cannot be 0.",
|
||||
new string[] { nameof(StorageGbAdjustment) });
|
||||
|
@ -33,16 +33,16 @@ namespace Bit.Core.Models.Api
|
||||
};
|
||||
|
||||
var posData = string.Empty;
|
||||
if(UserId.HasValue)
|
||||
if (UserId.HasValue)
|
||||
{
|
||||
posData = "userId:" + UserId.Value;
|
||||
}
|
||||
else if(OrganizationId.HasValue)
|
||||
else if (OrganizationId.HasValue)
|
||||
{
|
||||
posData = "organizationId:" + OrganizationId.Value;
|
||||
}
|
||||
|
||||
if(Credit)
|
||||
if (Credit)
|
||||
{
|
||||
posData += ",accountCredit:1";
|
||||
inv.ItemDesc = "Bitwarden Account Credit";
|
||||
@ -58,7 +58,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!UserId.HasValue && !OrganizationId.HasValue)
|
||||
if (!UserId.HasValue && !OrganizationId.HasValue)
|
||||
{
|
||||
yield return new ValidationResult("User or Ooganization is required.");
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public Cipher ToCipher(Cipher existingCipher)
|
||||
{
|
||||
switch(existingCipher.Type)
|
||||
switch (existingCipher.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
var loginObj = JObject.FromObject(new CipherLoginData(this),
|
||||
@ -90,29 +90,29 @@ namespace Bit.Core.Models.Api
|
||||
var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
|
||||
var hasAttachments = (Attachments?.Count ?? 0) > 0;
|
||||
|
||||
if(!hasAttachments2 && !hasAttachments)
|
||||
if (!hasAttachments2 && !hasAttachments)
|
||||
{
|
||||
return existingCipher;
|
||||
}
|
||||
|
||||
var attachments = existingCipher.GetAttachments();
|
||||
if((attachments?.Count ?? 0) == 0)
|
||||
if ((attachments?.Count ?? 0) == 0)
|
||||
{
|
||||
return existingCipher;
|
||||
}
|
||||
|
||||
if(hasAttachments2)
|
||||
if (hasAttachments2)
|
||||
{
|
||||
foreach(var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
|
||||
foreach (var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
|
||||
{
|
||||
var attachment2 = Attachments2[attachment.Key];
|
||||
attachment.Value.FileName = attachment2.FileName;
|
||||
attachment.Value.Key = attachment2.Key;
|
||||
}
|
||||
}
|
||||
else if(hasAttachments)
|
||||
else if (hasAttachments)
|
||||
{
|
||||
foreach(var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
|
||||
foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
|
||||
{
|
||||
attachment.Value.FileName = Attachments[attachment.Key];
|
||||
attachment.Value.Key = null;
|
||||
@ -125,7 +125,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public Cipher ToOrganizationCipher()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(OrganizationId));
|
||||
}
|
||||
@ -162,7 +162,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
|
||||
if (!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
@ -179,13 +179,13 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Cipher.OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(Cipher.OrganizationId))
|
||||
{
|
||||
yield return new ValidationResult("Cipher OrganizationId is required.",
|
||||
new string[] { nameof(Cipher.OrganizationId) });
|
||||
}
|
||||
|
||||
if(!CollectionIds?.Any() ?? true)
|
||||
if (!CollectionIds?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
@ -221,7 +221,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Ciphers?.Any() ?? true)
|
||||
if (!Ciphers?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one cipher.",
|
||||
new string[] { nameof(Ciphers) });
|
||||
@ -230,27 +230,27 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
var allHaveIds = true;
|
||||
var organizationIds = new HashSet<string>();
|
||||
foreach(var c in Ciphers)
|
||||
foreach (var c in Ciphers)
|
||||
{
|
||||
organizationIds.Add(c.OrganizationId);
|
||||
if(allHaveIds)
|
||||
if (allHaveIds)
|
||||
{
|
||||
allHaveIds = !(!c.Id.HasValue || string.IsNullOrWhiteSpace(c.OrganizationId));
|
||||
}
|
||||
}
|
||||
|
||||
if(!allHaveIds)
|
||||
if (!allHaveIds)
|
||||
{
|
||||
yield return new ValidationResult("All Ciphers must have an Id and OrganizationId.",
|
||||
new string[] { nameof(Ciphers) });
|
||||
}
|
||||
else if(organizationIds.Count != 1)
|
||||
else if (organizationIds.Count != 1)
|
||||
{
|
||||
yield return new ValidationResult("All ciphers must be for the same organization.");
|
||||
}
|
||||
}
|
||||
|
||||
if(!CollectionIds?.Any() ?? true)
|
||||
if (!CollectionIds?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(PaymentMethodType != Enums.PaymentMethodType.AppleInApp)
|
||||
if (PaymentMethodType != Enums.PaymentMethodType.AppleInApp)
|
||||
{
|
||||
yield return new ValidationResult("Not a supported in-app purchase payment method.",
|
||||
new string[] { nameof(PaymentMethodType) });
|
||||
|
@ -62,7 +62,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Email) && !Deleted)
|
||||
if (string.IsNullOrWhiteSpace(Email) && !Deleted)
|
||||
{
|
||||
yield return new ValidationResult("Email is required for enabled users.", new string[] { nameof(Email) });
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(PlanType != PlanType.Free && string.IsNullOrWhiteSpace(PaymentToken))
|
||||
if (PlanType != PlanType.Free && string.IsNullOrWhiteSpace(PaymentToken))
|
||||
{
|
||||
yield return new ValidationResult("Payment required.", new string[] { nameof(PaymentToken) });
|
||||
}
|
||||
if(PlanType != PlanType.Free && !PaymentMethodType.HasValue)
|
||||
if (PlanType != PlanType.Free && !PaymentMethodType.HasValue)
|
||||
{
|
||||
yield return new ValidationResult("Payment method type required.",
|
||||
new string[] { nameof(PaymentMethodType) });
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(SeatAdjustment == 0)
|
||||
if (SeatAdjustment == 0)
|
||||
{
|
||||
yield return new ValidationResult("Seat adjustment cannot be 0.", new string[] { nameof(SeatAdjustment) });
|
||||
}
|
||||
|
@ -17,26 +17,26 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Emails.Any())
|
||||
if (!Emails.Any())
|
||||
{
|
||||
yield return new ValidationResult("An email is required.");
|
||||
}
|
||||
|
||||
if(Emails.Count() > 20)
|
||||
if (Emails.Count() > 20)
|
||||
{
|
||||
yield return new ValidationResult("You can only invite up to 20 users at a time.");
|
||||
}
|
||||
|
||||
var attr = new EmailAddressAttribute();
|
||||
for(var i = 0; i < Emails.Count(); i++)
|
||||
for (var i = 0; i < Emails.Count(); i++)
|
||||
{
|
||||
var email = Emails.ElementAt(i);
|
||||
if(!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
|
||||
if (!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is not valid.",
|
||||
new string[] { nameof(Emails) });
|
||||
}
|
||||
else if(email.Length > 50)
|
||||
else if (email.Length > 50)
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is longer than 50 characters.",
|
||||
new string[] { nameof(Emails) });
|
||||
|
@ -17,7 +17,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
yield return new ValidationResult($"{nameof(UserId)} or {nameof(OrganizationId)} is required.");
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Authenticator))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Authenticator))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Authenticator);
|
||||
}
|
||||
@ -52,11 +52,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Duo))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Duo))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Duo);
|
||||
}
|
||||
@ -78,11 +78,11 @@ namespace Bit.Core.Models.Api
|
||||
public Organization ToOrganization(Organization extistingOrg)
|
||||
{
|
||||
var providers = extistingOrg.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.OrganizationDuo))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.OrganizationDuo))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.OrganizationDuo);
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Host.StartsWith("api-") || !Host.EndsWith(".duosecurity.com"))
|
||||
if (!Host.StartsWith("api-") || !Host.EndsWith(".duosecurity.com"))
|
||||
{
|
||||
yield return new ValidationResult("Host is invalid.", new string[] { nameof(Host) });
|
||||
}
|
||||
@ -123,11 +123,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.YubiKey))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.YubiKey))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.YubiKey);
|
||||
}
|
||||
@ -151,7 +151,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
private string FormatKey(string keyValue)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(keyValue))
|
||||
if (string.IsNullOrWhiteSpace(keyValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -161,33 +161,33 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Key1) && string.IsNullOrWhiteSpace(Key2) && string.IsNullOrWhiteSpace(Key3) &&
|
||||
if (string.IsNullOrWhiteSpace(Key1) && string.IsNullOrWhiteSpace(Key2) && string.IsNullOrWhiteSpace(Key3) &&
|
||||
string.IsNullOrWhiteSpace(Key4) && string.IsNullOrWhiteSpace(Key5))
|
||||
{
|
||||
yield return new ValidationResult("A key is required.", new string[] { nameof(Key1) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key1) && Key1.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key1) && Key1.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 1 in invalid.", new string[] { nameof(Key1) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key2) && Key2.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key2) && Key2.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 2 in invalid.", new string[] { nameof(Key2) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key3) && Key3.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key3) && Key3.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 3 in invalid.", new string[] { nameof(Key3) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key4) && Key4.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key4) && Key4.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 4 in invalid.", new string[] { nameof(Key4) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key5) && Key5.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key5) && Key5.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 5 in invalid.", new string[] { nameof(Key5) });
|
||||
}
|
||||
@ -204,11 +204,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Email))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Email))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Email);
|
||||
}
|
||||
@ -237,7 +237,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Id.HasValue || Id < 0 || Id > 5)
|
||||
if (!Id.HasValue || Id < 0 || Id > 5)
|
||||
{
|
||||
yield return new ValidationResult("Invalid Key Id", new string[] { nameof(Id) });
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
|
||||
public ApiKeyResponseModel(Organization organization, string obj = "apiKey")
|
||||
: base(obj)
|
||||
{
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organization));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace Bit.Core.Models.Api
|
||||
public static IEnumerable<AttachmentResponseModel> FromCipher(Cipher cipher, GlobalSettings globalSettings)
|
||||
{
|
||||
var attachments = cipher.GetAttachments();
|
||||
if(attachments == null)
|
||||
if (attachments == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Bit.Core.Models.Api
|
||||
public CipherMiniResponseModel(Cipher cipher, GlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
}
|
||||
@ -22,7 +22,7 @@ namespace Bit.Core.Models.Api
|
||||
Type = cipher.Type;
|
||||
|
||||
CipherData cipherData;
|
||||
switch(cipher.Type)
|
||||
switch (cipher.Type)
|
||||
{
|
||||
case Enums.CipherType.Login:
|
||||
var loginData = JsonConvert.DeserializeObject<CipherLoginData>(cipher.Data);
|
||||
@ -100,7 +100,7 @@ namespace Bit.Core.Models.Api
|
||||
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherDetails")
|
||||
: base(cipher, globalSettings, obj)
|
||||
{
|
||||
if(collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
{
|
||||
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
||||
}
|
||||
@ -126,7 +126,7 @@ namespace Bit.Core.Models.Api
|
||||
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherMiniDetails")
|
||||
: base(cipher, globalSettings, false, obj)
|
||||
{
|
||||
if(collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
{
|
||||
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public CollectionResponseModel(Collection collection, string obj = "collection")
|
||||
: base(obj)
|
||||
{
|
||||
if(collection == null)
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(collection));
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Bit.Core.Models.Api
|
||||
public DeviceResponseModel(Device device)
|
||||
: base("device")
|
||||
{
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(device));
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api
|
||||
public DomainsResponseModel(User user, bool excluded = true)
|
||||
: base("domains")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -26,7 +26,7 @@ namespace Bit.Core.Models.Api
|
||||
var globalDomains = new List<GlobalDomains>();
|
||||
var domainsToInclude = excluded ? Core.Utilities.StaticStore.GlobalDomains :
|
||||
Core.Utilities.StaticStore.GlobalDomains.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
|
||||
foreach(var domain in domainsToInclude)
|
||||
foreach (var domain in domainsToInclude)
|
||||
{
|
||||
globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded));
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ namespace Bit.Core.Models.Api
|
||||
var keys = modelState.Keys.ToList();
|
||||
var values = modelState.Values.ToList();
|
||||
|
||||
for(var i = 0; i < values.Count; i++)
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
{
|
||||
var value = values[i];
|
||||
|
||||
if(keys.Count <= i)
|
||||
if (keys.Count <= i)
|
||||
{
|
||||
// Keys not available for some reason.
|
||||
break;
|
||||
@ -37,7 +37,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
var key = keys[i];
|
||||
|
||||
if(value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
if (value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Bit.Core.Models.Api
|
||||
public EventResponseModel(IEvent ev)
|
||||
: base("event")
|
||||
{
|
||||
if(ev == null)
|
||||
if (ev == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ev));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
|
||||
public FolderResponseModel(Folder folder)
|
||||
: base("folder")
|
||||
{
|
||||
if(folder == null)
|
||||
if (folder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(folder));
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public GroupResponseModel(Group group, string obj = "group")
|
||||
: base(obj)
|
||||
{
|
||||
if(group == null)
|
||||
if (group == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(group));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
|
||||
public KeysResponseModel(User user)
|
||||
: base("keys")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public OrganizationResponseModel(Organization organization, string obj = "organization")
|
||||
: base(obj)
|
||||
{
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organization));
|
||||
}
|
||||
@ -71,7 +71,7 @@ namespace Bit.Core.Models.Api
|
||||
public OrganizationSubscriptionResponseModel(Organization organization, SubscriptionInfo subscription = null)
|
||||
: base(organization, "organizationSubscription")
|
||||
{
|
||||
if(subscription != null)
|
||||
if (subscription != null)
|
||||
{
|
||||
Subscription = subscription.Subscription != null ?
|
||||
new BillingSubscription(subscription.Subscription) : null;
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api
|
||||
public OrganizationUserResponseModel(OrganizationUser organizationUser, string obj = "organizationUser")
|
||||
: base(obj)
|
||||
{
|
||||
if(organizationUser == null)
|
||||
if (organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
@ -27,7 +27,7 @@ namespace Bit.Core.Models.Api
|
||||
public OrganizationUserResponseModel(OrganizationUserUserDetails organizationUser, string obj = "organizationUser")
|
||||
: base(obj)
|
||||
{
|
||||
if(organizationUser == null)
|
||||
if (organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace Bit.Core.Models.Api
|
||||
bool twoFactorEnabled, string obj = "organizationUserUserDetails")
|
||||
: base(organizationUser, obj)
|
||||
{
|
||||
if(organizationUser == null)
|
||||
if (organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public PolicyResponseModel(Policy policy, string obj = "policy")
|
||||
: base(obj)
|
||||
{
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(policy));
|
||||
}
|
||||
@ -20,7 +20,7 @@ namespace Bit.Core.Models.Api
|
||||
OrganizationId = policy.OrganizationId.ToString();
|
||||
Type = policy.Type;
|
||||
Enabled = policy.Enabled;
|
||||
if(!string.IsNullOrWhiteSpace(policy.Data))
|
||||
if (!string.IsNullOrWhiteSpace(policy.Data))
|
||||
{
|
||||
Data = JsonConvert.DeserializeObject<Dictionary<string, object>>(policy.Data);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Bit.Core.Models.Api
|
||||
IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails, bool twoFactorEnabled)
|
||||
: base("profile")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public ResponseModel(string obj)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(obj))
|
||||
if (string.IsNullOrWhiteSpace(obj))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public SelectionReadOnlyResponseModel(SelectionReadOnly selection)
|
||||
{
|
||||
if(selection == null)
|
||||
if (selection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(selection));
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Bit.Core.Models.Api
|
||||
MaxStorageGb = user.MaxStorageGb;
|
||||
Expiration = user.PremiumExpirationDate;
|
||||
|
||||
if(license != null)
|
||||
if (license != null)
|
||||
{
|
||||
License = license;
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace Bit.Core.Models.Api
|
||||
CancelledDate = sub.CancelledDate;
|
||||
CancelAtEndDate = sub.CancelAtEndDate;
|
||||
Cancelled = sub.Cancelled;
|
||||
if(sub.Items != null)
|
||||
if (sub.Items != null)
|
||||
{
|
||||
Items = sub.Items.Select(i => new BillingSubscriptionItem(i));
|
||||
}
|
||||
|
@ -10,13 +10,13 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorAuthenticatorResponseModel(User user)
|
||||
: base("twoFactorAuthenticator")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
|
||||
if(provider?.MetaData?.ContainsKey("Key") ?? false)
|
||||
if (provider?.MetaData?.ContainsKey("Key") ?? false)
|
||||
{
|
||||
Key = (string)provider.MetaData["Key"];
|
||||
Enabled = provider.Enabled;
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorDuoResponseModel(User user)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorDuoResponseModel(Organization org)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(org == null)
|
||||
if (org == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(org));
|
||||
}
|
||||
@ -39,19 +39,19 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
private void Build(TwoFactorProvider provider)
|
||||
{
|
||||
if(provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
if (provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
{
|
||||
Enabled = provider.Enabled;
|
||||
|
||||
if(provider.MetaData.ContainsKey("Host"))
|
||||
if (provider.MetaData.ContainsKey("Host"))
|
||||
{
|
||||
Host = (string)provider.MetaData["Host"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("SKey"))
|
||||
if (provider.MetaData.ContainsKey("SKey"))
|
||||
{
|
||||
SecretKey = (string)provider.MetaData["SKey"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("IKey"))
|
||||
if (provider.MetaData.ContainsKey("IKey"))
|
||||
{
|
||||
IntegrationKey = (string)provider.MetaData["IKey"];
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorEmailResponseModel(User user)
|
||||
: base("twoFactorEmail")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
|
||||
if(provider?.MetaData?.ContainsKey("Email") ?? false)
|
||||
if (provider?.MetaData?.ContainsKey("Email") ?? false)
|
||||
{
|
||||
Email = (string)provider.MetaData["Email"];
|
||||
Enabled = provider.Enabled;
|
||||
|
@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, TwoFactorProvider provider)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(provider == null)
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, User user)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
@ -36,7 +36,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, Organization organization)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organization));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorRecoverResponseModel(User user)
|
||||
: base("twoFactorRecover")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorU2fResponseModel(User user)
|
||||
: base("twoFactorU2f")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
@ -9,37 +9,37 @@ namespace Bit.Core.Models.Api
|
||||
public TwoFactorYubiKeyResponseModel(User user)
|
||||
: base("twoFactorYubiKey")
|
||||
{
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
|
||||
if(provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
if (provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
{
|
||||
Enabled = provider.Enabled;
|
||||
|
||||
if(provider.MetaData.ContainsKey("Key1"))
|
||||
if (provider.MetaData.ContainsKey("Key1"))
|
||||
{
|
||||
Key1 = (string)provider.MetaData["Key1"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("Key2"))
|
||||
if (provider.MetaData.ContainsKey("Key2"))
|
||||
{
|
||||
Key2 = (string)provider.MetaData["Key2"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("Key3"))
|
||||
if (provider.MetaData.ContainsKey("Key3"))
|
||||
{
|
||||
Key3 = (string)provider.MetaData["Key3"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("Key4"))
|
||||
if (provider.MetaData.ContainsKey("Key4"))
|
||||
{
|
||||
Key4 = (string)provider.MetaData["Key4"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("Key5"))
|
||||
if (provider.MetaData.ContainsKey("Key5"))
|
||||
{
|
||||
Key5 = (string)provider.MetaData["Key5"];
|
||||
}
|
||||
if(provider.MetaData.ContainsKey("Nfc"))
|
||||
if (provider.MetaData.ContainsKey("Nfc"))
|
||||
{
|
||||
Nfc = (bool)provider.MetaData["Nfc"];
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace Bit.Billing.Models
|
||||
{
|
||||
var cancellationDate = GetLastCancellationDate();
|
||||
var expiresDate = GetLastCancellationDate();
|
||||
if(cancellationDate.HasValue && expiresDate.HasValue)
|
||||
if (cancellationDate.HasValue && expiresDate.HasValue)
|
||||
{
|
||||
return cancellationDate.Value <= expiresDate.Value;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public BillingSource(PaymentMethod method)
|
||||
{
|
||||
if(method.Card != null)
|
||||
if (method.Card != null)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{method.Card.Brand?.ToUpperInvariant()}, *{method.Card.Last4}, " +
|
||||
@ -33,7 +33,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public BillingSource(IPaymentSource source)
|
||||
{
|
||||
if(source is BankAccount bankAccount)
|
||||
if (source is BankAccount bankAccount)
|
||||
{
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{bankAccount.BankName}, *{bankAccount.Last4} - " +
|
||||
@ -42,7 +42,7 @@ namespace Bit.Core.Models.Business
|
||||
bankAccount.Status == "verification_failed" ? "verification failed" : "unverified");
|
||||
NeedsVerification = bankAccount.Status == "new" || bankAccount.Status == "validated";
|
||||
}
|
||||
else if(source is Card card)
|
||||
else if (source is Card card)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{card.Brand}, *{card.Last4}, " +
|
||||
@ -52,7 +52,7 @@ namespace Bit.Core.Models.Business
|
||||
card.ExpYear);
|
||||
CardBrand = card.Brand;
|
||||
}
|
||||
else if(source is Source src && src.Card != null)
|
||||
else if (source is Source src && src.Card != null)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{src.Card.Brand}, *{src.Card.Last4}, " +
|
||||
@ -66,12 +66,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public BillingSource(Braintree.PaymentMethod method)
|
||||
{
|
||||
if(method is Braintree.PayPalAccount paypal)
|
||||
if (method is Braintree.PayPalAccount paypal)
|
||||
{
|
||||
Type = PaymentMethodType.PayPal;
|
||||
Description = paypal.Email;
|
||||
}
|
||||
else if(method is Braintree.CreditCard card)
|
||||
else if (method is Braintree.CreditCard card)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{card.CardType.ToString()}, *{card.LastFour}, " +
|
||||
@ -81,7 +81,7 @@ namespace Bit.Core.Models.Business
|
||||
card.ExpirationYear);
|
||||
CardBrand = card.CardType.ToString();
|
||||
}
|
||||
else if(method is Braintree.UsBankAccount bank)
|
||||
else if (method is Braintree.UsBankAccount bank)
|
||||
{
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{bank.BankName}, *{bank.Last4}";
|
||||
|
@ -43,9 +43,9 @@ namespace Bit.Core.Models.Business
|
||||
UsersGetPremium = org.UsersGetPremium;
|
||||
Issued = DateTime.UtcNow;
|
||||
|
||||
if(subscriptionInfo?.Subscription == null)
|
||||
if (subscriptionInfo?.Subscription == null)
|
||||
{
|
||||
if(org.PlanType == PlanType.Custom && org.ExpirationDate.HasValue)
|
||||
if (org.PlanType == PlanType.Custom && org.ExpirationDate.HasValue)
|
||||
{
|
||||
Expires = Refresh = org.ExpirationDate.Value;
|
||||
Trial = false;
|
||||
@ -56,7 +56,7 @@ namespace Bit.Core.Models.Business
|
||||
Trial = true;
|
||||
}
|
||||
}
|
||||
else if(subscriptionInfo.Subscription.TrialEndDate.HasValue &&
|
||||
else if (subscriptionInfo.Subscription.TrialEndDate.HasValue &&
|
||||
subscriptionInfo.Subscription.TrialEndDate.Value > DateTime.UtcNow)
|
||||
{
|
||||
Expires = Refresh = subscriptionInfo.Subscription.TrialEndDate.Value;
|
||||
@ -64,12 +64,12 @@ namespace Bit.Core.Models.Business
|
||||
}
|
||||
else
|
||||
{
|
||||
if(org.ExpirationDate.HasValue && org.ExpirationDate.Value < DateTime.UtcNow)
|
||||
if (org.ExpirationDate.HasValue && org.ExpirationDate.Value < DateTime.UtcNow)
|
||||
{
|
||||
// expired
|
||||
Expires = Refresh = org.ExpirationDate.Value;
|
||||
}
|
||||
else if(subscriptionInfo?.Subscription?.PeriodDuration != null &&
|
||||
else if (subscriptionInfo?.Subscription?.PeriodDuration != null &&
|
||||
subscriptionInfo.Subscription.PeriodDuration > TimeSpan.FromDays(180))
|
||||
{
|
||||
Refresh = DateTime.UtcNow.AddDays(30);
|
||||
@ -122,7 +122,7 @@ namespace Bit.Core.Models.Business
|
||||
public byte[] GetDataBytes(bool forHash = false)
|
||||
{
|
||||
string data = null;
|
||||
if(Version >= 1 && Version <= 6)
|
||||
if (Version >= 1 && Version <= 6)
|
||||
{
|
||||
var props = typeof(OrganizationLicense)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
@ -162,7 +162,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public byte[] ComputeHash()
|
||||
{
|
||||
using(var alg = SHA256.Create())
|
||||
using (var alg = SHA256.Create())
|
||||
{
|
||||
return alg.ComputeHash(GetDataBytes(true));
|
||||
}
|
||||
@ -170,12 +170,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool CanUse(GlobalSettings globalSettings)
|
||||
{
|
||||
if(!Enabled || Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
if (!Enabled || Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version >= 1 && Version <= 6)
|
||||
if (Version >= 1 && Version <= 6)
|
||||
{
|
||||
return InstallationId == globalSettings.Installation.Id && SelfHost;
|
||||
}
|
||||
@ -187,12 +187,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool VerifyData(Organization organization, GlobalSettings globalSettings)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
if (Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version >= 1 && Version <= 6)
|
||||
if (Version >= 1 && Version <= 6)
|
||||
{
|
||||
var valid =
|
||||
globalSettings.Installation.Id == InstallationId &&
|
||||
@ -207,27 +207,27 @@ namespace Bit.Core.Models.Business
|
||||
organization.SelfHost == SelfHost &&
|
||||
organization.Name.Equals(Name);
|
||||
|
||||
if(valid && Version >= 2)
|
||||
if (valid && Version >= 2)
|
||||
{
|
||||
valid = organization.UsersGetPremium == UsersGetPremium;
|
||||
}
|
||||
|
||||
if(valid && Version >= 3)
|
||||
if (valid && Version >= 3)
|
||||
{
|
||||
valid = organization.UseEvents == UseEvents;
|
||||
}
|
||||
|
||||
if(valid && Version >= 4)
|
||||
if (valid && Version >= 4)
|
||||
{
|
||||
valid = organization.Use2fa == Use2fa;
|
||||
}
|
||||
|
||||
if(valid && Version >= 5)
|
||||
if (valid && Version >= 5)
|
||||
{
|
||||
valid = organization.UseApi == UseApi;
|
||||
}
|
||||
|
||||
if(valid && Version >= 6)
|
||||
if (valid && Version >= 6)
|
||||
{
|
||||
valid = organization.UsePolicies == UsePolicies;
|
||||
}
|
||||
@ -242,7 +242,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool VerifySignature(X509Certificate2 certificate)
|
||||
{
|
||||
using(var rsa = certificate.GetRSAPublicKey())
|
||||
using (var rsa = certificate.GetRSAPublicKey())
|
||||
{
|
||||
return rsa.VerifyData(GetDataBytes(), SignatureBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
}
|
||||
@ -250,12 +250,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public byte[] Sign(X509Certificate2 certificate)
|
||||
{
|
||||
if(!certificate.HasPrivateKey)
|
||||
if (!certificate.HasPrivateKey)
|
||||
{
|
||||
throw new InvalidOperationException("You don't have the private key!");
|
||||
}
|
||||
|
||||
using(var rsa = certificate.GetRSAPrivateKey())
|
||||
using (var rsa = certificate.GetRSAPrivateKey())
|
||||
{
|
||||
return rsa.SignData(GetDataBytes(), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace Bit.Core.Models.Business
|
||||
CancelledDate = sub.CanceledAt;
|
||||
CancelAtEndDate = sub.CancelAtPeriodEnd;
|
||||
Cancelled = sub.Status == "canceled" || sub.Status == "unpaid" || sub.Status == "incomplete_expired";
|
||||
if(sub.Items?.Data != null)
|
||||
if (sub.Items?.Data != null)
|
||||
{
|
||||
Items = sub.Items.Data.Select(i => new BillingSubscriptionItem(i));
|
||||
}
|
||||
@ -44,7 +44,7 @@ namespace Bit.Core.Models.Business
|
||||
{
|
||||
public BillingSubscriptionItem(SubscriptionItem item)
|
||||
{
|
||||
if(item.Plan != null)
|
||||
if (item.Plan != null)
|
||||
{
|
||||
Name = item.Plan.Nickname;
|
||||
Amount = item.Plan.Amount.GetValueOrDefault() / 100M;
|
||||
@ -74,7 +74,7 @@ namespace Bit.Core.Models.Business
|
||||
public BillingUpcomingInvoice(Braintree.Subscription sub)
|
||||
{
|
||||
Amount = sub.NextBillAmount.GetValueOrDefault() + sub.Balance.GetValueOrDefault();
|
||||
if(Amount < 0)
|
||||
if (Amount < 0)
|
||||
{
|
||||
Amount = 0;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ namespace Bit.Core.Models.Business
|
||||
public byte[] GetDataBytes(bool forHash = false)
|
||||
{
|
||||
string data = null;
|
||||
if(Version == 1)
|
||||
if (Version == 1)
|
||||
{
|
||||
var props = typeof(UserLicense)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
@ -101,7 +101,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public byte[] ComputeHash()
|
||||
{
|
||||
using(var alg = SHA256.Create())
|
||||
using (var alg = SHA256.Create())
|
||||
{
|
||||
return alg.ComputeHash(GetDataBytes(true));
|
||||
}
|
||||
@ -109,12 +109,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool CanUse(User user)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
if (Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
if (Version == 1)
|
||||
{
|
||||
return user.EmailVerified && user.Email.Equals(Email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
@ -126,12 +126,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool VerifyData(User user)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
if (Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
if (Version == 1)
|
||||
{
|
||||
return
|
||||
user.LicenseKey != null && user.LicenseKey.Equals(LicenseKey) &&
|
||||
@ -146,7 +146,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public bool VerifySignature(X509Certificate2 certificate)
|
||||
{
|
||||
using(var rsa = certificate.GetRSAPublicKey())
|
||||
using (var rsa = certificate.GetRSAPublicKey())
|
||||
{
|
||||
return rsa.VerifyData(GetDataBytes(), SignatureBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
}
|
||||
@ -154,12 +154,12 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public byte[] Sign(X509Certificate2 certificate)
|
||||
{
|
||||
if(!certificate.HasPrivateKey)
|
||||
if (!certificate.HasPrivateKey)
|
||||
{
|
||||
throw new InvalidOperationException("You don't have the private key!");
|
||||
}
|
||||
|
||||
using(var rsa = certificate.GetRSAPrivateKey())
|
||||
using (var rsa = certificate.GetRSAPrivateKey())
|
||||
{
|
||||
return rsa.SignData(GetDataBytes(), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace Bit.Core.Models.Data
|
||||
var result = base.WriteEntity(operationContext);
|
||||
|
||||
var typeName = nameof(Type);
|
||||
if(result.ContainsKey(typeName))
|
||||
if (result.ContainsKey(typeName))
|
||||
{
|
||||
result[typeName] = new EntityProperty((int)Type);
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace Bit.Core.Models.Data
|
||||
}
|
||||
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if(result.ContainsKey(deviceTypeName))
|
||||
if (result.ContainsKey(deviceTypeName))
|
||||
{
|
||||
result[deviceTypeName] = new EntityProperty((int?)DeviceType);
|
||||
}
|
||||
@ -72,13 +72,13 @@ namespace Bit.Core.Models.Data
|
||||
base.ReadEntity(properties, operationContext);
|
||||
|
||||
var typeName = nameof(Type);
|
||||
if(properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
|
||||
if (properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
|
||||
{
|
||||
Type = (EventType)properties[typeName].Int32Value.Value;
|
||||
}
|
||||
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if(properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
|
||||
if (properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
|
||||
{
|
||||
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
|
||||
}
|
||||
@ -99,7 +99,7 @@ namespace Bit.Core.Models.Data
|
||||
}
|
||||
};
|
||||
|
||||
if(e.OrganizationId.HasValue && e.ActingUserId.HasValue)
|
||||
if (e.OrganizationId.HasValue && e.ActingUserId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
{
|
||||
@ -109,7 +109,7 @@ namespace Bit.Core.Models.Data
|
||||
});
|
||||
}
|
||||
|
||||
if(e.CipherId.HasValue)
|
||||
if (e.CipherId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
{
|
||||
|
@ -16,11 +16,11 @@ namespace Bit.Core.Models.Data
|
||||
public InstallationDeviceEntity(string prefixedDeviceId)
|
||||
{
|
||||
var parts = prefixedDeviceId.Split("_");
|
||||
if(parts.Length < 2)
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
throw new ArgumentException("Not enough parts.");
|
||||
}
|
||||
if(!Guid.TryParse(parts[0], out var installationId) || !Guid.TryParse(parts[1], out var deviceId))
|
||||
if (!Guid.TryParse(parts[0], out var installationId) || !Guid.TryParse(parts[1], out var deviceId))
|
||||
{
|
||||
throw new ArgumentException("Could not parse parts.");
|
||||
}
|
||||
|
@ -23,14 +23,14 @@ namespace Bit.Core.Models.Data
|
||||
|
||||
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(_twoFactorProviders == null)
|
||||
if (_twoFactorProviders == null)
|
||||
{
|
||||
_twoFactorProviders =
|
||||
JsonConvert.DeserializeObject<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(
|
||||
@ -39,7 +39,7 @@ namespace Bit.Core.Models.Data
|
||||
|
||||
return _twoFactorProviders;
|
||||
}
|
||||
catch(JsonSerializationException)
|
||||
catch (JsonSerializationException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Bit.Core.Models.Mail
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Uri.TryCreate(WebVaultUrl, UriKind.Absolute, out Uri uri))
|
||||
if (Uri.TryCreate(WebVaultUrl, UriKind.Absolute, out Uri uri))
|
||||
{
|
||||
return uri.Host;
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public Dictionary<string, CipherAttachment.MetaData> GetAttachments()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Attachments))
|
||||
if (string.IsNullOrWhiteSpace(Attachments))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(_attachmentData != null)
|
||||
if (_attachmentData != null)
|
||||
{
|
||||
return _attachmentData;
|
||||
}
|
||||
@ -51,7 +51,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public void SetAttachments(Dictionary<string, CipherAttachment.MetaData> data)
|
||||
{
|
||||
if(data == null || data.Count == 0)
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
_attachmentData = null;
|
||||
Attachments = null;
|
||||
@ -65,7 +65,7 @@ namespace Bit.Core.Models.Table
|
||||
public void AddAttachment(string id, CipherAttachment.MetaData data)
|
||||
{
|
||||
var attachments = GetAttachments();
|
||||
if(attachments == null)
|
||||
if (attachments == null)
|
||||
{
|
||||
attachments = new Dictionary<string, CipherAttachment.MetaData>();
|
||||
}
|
||||
@ -77,7 +77,7 @@ namespace Bit.Core.Models.Table
|
||||
public void DeleteAttachment(string id)
|
||||
{
|
||||
var attachments = GetAttachments();
|
||||
if(!attachments?.ContainsKey(id) ?? true)
|
||||
if (!attachments?.ContainsKey(id) ?? true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
if(Id == default(Guid))
|
||||
if (Id == default(Guid))
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
@ -86,7 +86,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public long StorageBytesRemaining()
|
||||
{
|
||||
if(!MaxStorageGb.HasValue)
|
||||
if (!MaxStorageGb.HasValue)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -97,7 +97,7 @@ namespace Bit.Core.Models.Table
|
||||
public long StorageBytesRemaining(short maxStorageGb)
|
||||
{
|
||||
var maxStorageBytes = maxStorageGb * 1073741824L;
|
||||
if(!Storage.HasValue)
|
||||
if (!Storage.HasValue)
|
||||
{
|
||||
return maxStorageBytes;
|
||||
}
|
||||
@ -107,14 +107,14 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(_twoFactorProviders == null)
|
||||
if (_twoFactorProviders == null)
|
||||
{
|
||||
_twoFactorProviders =
|
||||
JsonConvert.DeserializeObject<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(
|
||||
@ -123,7 +123,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
return _twoFactorProviders;
|
||||
}
|
||||
catch(JsonSerializationException)
|
||||
catch (JsonSerializationException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -131,7 +131,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public void SetTwoFactorProviders(Dictionary<TwoFactorProviderType, TwoFactorProvider> providers)
|
||||
{
|
||||
if(!providers.Any())
|
||||
if (!providers.Any())
|
||||
{
|
||||
TwoFactorProviders = null;
|
||||
_twoFactorProviders = null;
|
||||
@ -148,7 +148,7 @@ namespace Bit.Core.Models.Table
|
||||
public bool TwoFactorProviderIsEnabled(TwoFactorProviderType provider)
|
||||
{
|
||||
var providers = GetTwoFactorProviders();
|
||||
if(providers == null || !providers.ContainsKey(provider))
|
||||
if (providers == null || !providers.ContainsKey(provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -159,7 +159,7 @@ namespace Bit.Core.Models.Table
|
||||
public bool TwoFactorIsEnabled()
|
||||
{
|
||||
var providers = GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -170,7 +170,7 @@ namespace Bit.Core.Models.Table
|
||||
public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider)
|
||||
{
|
||||
var providers = GetTwoFactorProviders();
|
||||
if(providers == null || !providers.ContainsKey(provider))
|
||||
if (providers == null || !providers.ContainsKey(provider))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -80,14 +80,14 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(_twoFactorProviders == null)
|
||||
if (_twoFactorProviders == null)
|
||||
{
|
||||
_twoFactorProviders =
|
||||
JsonConvert.DeserializeObject<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(
|
||||
@ -96,7 +96,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
return _twoFactorProviders;
|
||||
}
|
||||
catch(JsonSerializationException)
|
||||
catch (JsonSerializationException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -124,7 +124,7 @@ namespace Bit.Core.Models.Table
|
||||
public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider)
|
||||
{
|
||||
var providers = GetTwoFactorProviders();
|
||||
if(providers == null || !providers.ContainsKey(provider))
|
||||
if (providers == null || !providers.ContainsKey(provider))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -134,7 +134,7 @@ namespace Bit.Core.Models.Table
|
||||
|
||||
public long StorageBytesRemaining()
|
||||
{
|
||||
if(!MaxStorageGb.HasValue)
|
||||
if (!MaxStorageGb.HasValue)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -145,7 +145,7 @@ namespace Bit.Core.Models.Table
|
||||
public long StorageBytesRemaining(short maxStorageGb)
|
||||
{
|
||||
var maxStorageBytes = maxStorageGb * 1073741824L;
|
||||
if(!Storage.HasValue)
|
||||
if (!Storage.HasValue)
|
||||
{
|
||||
return maxStorageBytes;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace Bit.Core.Models
|
||||
|
||||
public static bool RequiresPremium(TwoFactorProviderType type)
|
||||
{
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case TwoFactorProviderType.Duo:
|
||||
case TwoFactorProviderType.YubiKey:
|
||||
|
@ -12,11 +12,11 @@ namespace Bit.Core.Repositories
|
||||
|
||||
public BaseRepository(string connectionString, string readOnlyConnectionString)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(connectionString))
|
||||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(connectionString));
|
||||
}
|
||||
if(string.IsNullOrWhiteSpace(readOnlyConnectionString))
|
||||
if (string.IsNullOrWhiteSpace(readOnlyConnectionString))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(readOnlyConnectionString));
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<ICollection<TableModel.Organization>> GetManyByEnabledAsync()
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var organizations = await GetDbSet(dbContext).Where(e => e.Enabled).ToListAsync();
|
||||
@ -36,7 +36,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
public async Task<ICollection<TableModel.Organization>> SearchAsync(string name, string userEmail, bool? paid,
|
||||
int skip, int take)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
// TODO: more filters
|
||||
@ -51,7 +51,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task UpdateStorageAsync(Guid id)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var ciphers = await dbContext.Ciphers
|
||||
@ -75,7 +75,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<ICollection<DataModel.OrganizationAbility>> GetManyAbilitiesAsync()
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
return await GetDbSet(dbContext)
|
||||
|
@ -22,7 +22,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public virtual async Task<T> GetByIdAsync(TId id)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var entity = await GetDbSet(dbContext).FindAsync(id);
|
||||
@ -32,7 +32,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public virtual async Task CreateAsync(T obj)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var entity = Mapper.Map<TEntity>(obj);
|
||||
@ -44,11 +44,11 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public virtual async Task ReplaceAsync(T obj)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var entity = await GetDbSet(dbContext).FindAsync(obj.Id);
|
||||
if(entity != null)
|
||||
if (entity != null)
|
||||
{
|
||||
var mappedEntity = Mapper.Map<TEntity>(obj);
|
||||
dbContext.Entry(entity).CurrentValues.SetValues(mappedEntity);
|
||||
@ -59,7 +59,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public virtual async Task UpsertAsync(T obj)
|
||||
{
|
||||
if(obj.Id.Equals(default(T)))
|
||||
if (obj.Id.Equals(default(T)))
|
||||
{
|
||||
await CreateAsync(obj);
|
||||
}
|
||||
@ -71,7 +71,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public virtual async Task DeleteAsync(T obj)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var entity = Mapper.Map<TEntity>(obj);
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<TableModel.User> GetByEmailAsync(string email)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
return await GetDbSet(dbContext).FirstOrDefaultAsync(e => e.Email == email);
|
||||
@ -28,7 +28,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<DataModel.UserKdfInformation> GetKdfInformationByEmailAsync(string email)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
return await GetDbSet(dbContext).Where(e => e.Email == email)
|
||||
@ -42,7 +42,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<ICollection<TableModel.User>> SearchAsync(string email, int skip, int take)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var users = await GetDbSet(dbContext)
|
||||
@ -56,7 +56,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<ICollection<TableModel.User>> GetManyByPremiumAsync(bool premium)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var users = await GetDbSet(dbContext).Where(e => e.Premium == premium).ToListAsync();
|
||||
@ -66,7 +66,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<string> GetPublicKeyAsync(Guid id)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
return await GetDbSet(dbContext).Where(e => e.Id == id).Select(e => e.PublicKey).SingleOrDefaultAsync();
|
||||
@ -75,7 +75,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task<DateTime> GetAccountRevisionDateAsync(Guid id)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
return await GetDbSet(dbContext).Where(e => e.Id == id).Select(e => e.AccountRevisionDate)
|
||||
@ -85,7 +85,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task UpdateStorageAsync(Guid id)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var ciphers = await dbContext.Ciphers.Where(e => e.UserId == id).ToListAsync();
|
||||
@ -108,7 +108,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public async Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate)
|
||||
{
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var user = new EFModel.User
|
||||
|
@ -17,7 +17,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
protected static string SnakeCase(string input)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(input))
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return input;
|
||||
}
|
||||
@ -29,7 +29,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
{
|
||||
var dp = new DynamicParameters();
|
||||
var properties = typeof(T).GetProperties();
|
||||
foreach(var property in properties)
|
||||
foreach (var property in properties)
|
||||
{
|
||||
dp.Add($"_{SnakeCase(property.Name)}", property.GetValue(obj));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
public Repository(string connectionString, string readOnlyConnectionString, string table = null)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(table))
|
||||
if (!string.IsNullOrWhiteSpace(table))
|
||||
{
|
||||
Table = table;
|
||||
}
|
||||
@ -29,7 +29,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public virtual async Task<T> GetByIdAsync(TId id)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<T>(
|
||||
$"{Table}_read_by_id",
|
||||
@ -43,7 +43,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
public virtual async Task CreateAsync(T obj)
|
||||
{
|
||||
obj.SetNewId();
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"{Table}_create",
|
||||
@ -54,7 +54,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public virtual async Task ReplaceAsync(T obj)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"{Table}_update",
|
||||
@ -65,7 +65,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public virtual async Task UpsertAsync(T obj)
|
||||
{
|
||||
if(obj.Id.Equals(default(TId)))
|
||||
if (obj.Id.Equals(default(TId)))
|
||||
{
|
||||
await CreateAsync(obj);
|
||||
}
|
||||
@ -77,7 +77,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public virtual async Task DeleteAsync(T obj)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
$"{Table}_delete_by_id",
|
||||
|
@ -27,7 +27,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<User> GetByEmailAsync(string email)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<User>(
|
||||
"user_read_by_email",
|
||||
@ -40,7 +40,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<UserKdfInformation>(
|
||||
"user_read_kdf_by_email",
|
||||
@ -53,7 +53,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<ICollection<User>> SearchAsync(string email, int skip, int take)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ReadOnlyConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ReadOnlyConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<User>(
|
||||
"user_search",
|
||||
@ -67,7 +67,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<ICollection<User>> GetManyByPremiumAsync(bool premium)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<User>(
|
||||
"user_read_by_premium",
|
||||
@ -80,7 +80,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<ICollection<User>> GetManyByPremiumRenewalAsync()
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<User>(
|
||||
"user_read_by_premium_renewal",
|
||||
@ -92,7 +92,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<string> GetPublicKeyAsync(Guid id)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<string>(
|
||||
"user_read_public_key_by_id",
|
||||
@ -105,7 +105,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task<DateTime> GetAccountRevisionDateAsync(Guid id)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<DateTime>(
|
||||
"user_read_account_revision_date_by_id",
|
||||
@ -123,7 +123,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public override async Task DeleteAsync(User user)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
$"user_delete_by_id",
|
||||
@ -135,7 +135,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task UpdateStorageAsync(Guid id)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"user_update_storage",
|
||||
@ -147,7 +147,7 @@ namespace Bit.Core.Repositories.PostgreSql
|
||||
|
||||
public async Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate)
|
||||
{
|
||||
using(var connection = new NpgsqlConnection(ConnectionString))
|
||||
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"user_update_renewal_reminder_date",
|
||||
|
@ -25,7 +25,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<CipherDetails> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CipherDetails>(
|
||||
$"[{Schema}].[CipherDetails_ReadByIdUserId]",
|
||||
@ -38,7 +38,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id, bool deleted = false)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CipherDetails>(
|
||||
$"[{Schema}].[CipherOrganizationDetails_ReadById]",
|
||||
@ -51,7 +51,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var result = await connection.QueryFirstOrDefaultAsync<bool>(
|
||||
$"[{Schema}].[Cipher_ReadCanEditByIdUserId]",
|
||||
@ -65,7 +65,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true, bool deleted = false)
|
||||
{
|
||||
string sprocName = null;
|
||||
if(withOrganizations)
|
||||
if (withOrganizations)
|
||||
{
|
||||
sprocName = $"[{Schema}].[CipherDetails_ReadByUserId]";
|
||||
}
|
||||
@ -74,7 +74,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
sprocName = $"[{Schema}].[CipherDetails_ReadWithoutOrganizationsByUserId]";
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CipherDetails>(
|
||||
sprocName,
|
||||
@ -90,7 +90,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId, bool deleted = false)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Cipher>(
|
||||
$"[{Schema}].[Cipher_ReadByOrganizationId]",
|
||||
@ -107,7 +107,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithCollections = JsonConvert.DeserializeObject<CipherWithCollections>(
|
||||
JsonConvert.SerializeObject(cipher));
|
||||
objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_CreateWithCollections]",
|
||||
@ -119,7 +119,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task CreateAsync(CipherDetails cipher)
|
||||
{
|
||||
cipher.SetNewId();
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CipherDetails_Create]",
|
||||
@ -134,7 +134,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithCollections = JsonConvert.DeserializeObject<CipherDetailsWithCollections>(
|
||||
JsonConvert.SerializeObject(cipher));
|
||||
objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CipherDetails_CreateWithCollections]",
|
||||
@ -145,7 +145,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task ReplaceAsync(CipherDetails obj)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CipherDetails_Update]",
|
||||
@ -156,7 +156,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpsertAsync(CipherDetails cipher)
|
||||
{
|
||||
if(cipher.Id.Equals(default(Guid)))
|
||||
if (cipher.Id.Equals(default(Guid)))
|
||||
{
|
||||
await CreateAsync(cipher);
|
||||
}
|
||||
@ -172,7 +172,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
JsonConvert.SerializeObject(obj));
|
||||
objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var result = await connection.ExecuteScalarAsync<int>(
|
||||
$"[{Schema}].[Cipher_UpdateWithCollections]",
|
||||
@ -184,7 +184,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdatePartialAsync(Guid id, Guid userId, Guid? folderId, bool favorite)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_UpdatePartial]",
|
||||
@ -195,7 +195,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateAttachmentAsync(CipherAttachment attachment)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_UpdateAttachment]",
|
||||
@ -206,7 +206,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAttachmentAsync(Guid cipherId, string attachmentId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_DeleteAttachment]",
|
||||
@ -217,7 +217,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAsync(Cipher obj, bool permanent = true)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_DeleteById]",
|
||||
@ -228,7 +228,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAsync(IEnumerable<Guid> ids, Guid userId, bool permanent = true)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_Delete]",
|
||||
@ -239,7 +239,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task MoveAsync(IEnumerable<Guid> ids, Guid? folderId, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_Move]",
|
||||
@ -250,7 +250,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_DeleteByUserId]",
|
||||
@ -261,7 +261,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Cipher_DeleteByOrganizationId]",
|
||||
@ -272,24 +272,24 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public Task UpdateUserKeysAndCiphersAsync(User user, IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using(var transaction = connection.BeginTransaction())
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. Update user.
|
||||
|
||||
using(var cmd = new SqlCommand("[dbo].[User_UpdateKeys]", connection, transaction))
|
||||
using (var cmd = new SqlCommand("[dbo].[User_UpdateKeys]", connection, transaction))
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.Add("@Id", SqlDbType.UniqueIdentifier).Value = user.Id;
|
||||
cmd.Parameters.Add("@SecurityStamp", SqlDbType.NVarChar).Value = user.SecurityStamp;
|
||||
cmd.Parameters.Add("@Key", SqlDbType.VarChar).Value = user.Key;
|
||||
|
||||
if(string.IsNullOrWhiteSpace(user.PrivateKey))
|
||||
if (string.IsNullOrWhiteSpace(user.PrivateKey))
|
||||
{
|
||||
cmd.Parameters.Add("@PrivateKey", SqlDbType.VarChar).Value = DBNull.Value;
|
||||
}
|
||||
@ -313,16 +313,16 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
INTO #TempFolder
|
||||
FROM [dbo].[Folder]";
|
||||
|
||||
using(var cmd = new SqlCommand(sqlCreateTemp, connection, transaction))
|
||||
using (var cmd = new SqlCommand(sqlCreateTemp, connection, transaction))
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// 3. Bulk copy into temp tables.
|
||||
|
||||
if(ciphers.Any())
|
||||
if (ciphers.Any())
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "#TempCipher";
|
||||
var dataTable = BuildCiphersTable(bulkCopy, ciphers);
|
||||
@ -330,9 +330,9 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
if(folders.Any())
|
||||
if (folders.Any())
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "#TempFolder";
|
||||
var dataTable = BuildFoldersTable(bulkCopy, folders);
|
||||
@ -344,7 +344,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
var sql = string.Empty;
|
||||
|
||||
if(ciphers.Any())
|
||||
if (ciphers.Any())
|
||||
{
|
||||
sql += @"
|
||||
UPDATE
|
||||
@ -361,7 +361,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
C.[UserId] = @UserId";
|
||||
}
|
||||
|
||||
if(folders.Any())
|
||||
if (folders.Any())
|
||||
{
|
||||
sql += @"
|
||||
UPDATE
|
||||
@ -381,7 +381,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
DROP TABLE #TempCipher
|
||||
DROP TABLE #TempFolder";
|
||||
|
||||
using(var cmd = new SqlCommand(sql, connection, transaction))
|
||||
using (var cmd = new SqlCommand(sql, connection, transaction))
|
||||
{
|
||||
cmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = user.Id;
|
||||
cmd.ExecuteNonQuery();
|
||||
@ -402,16 +402,16 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateCiphersAsync(Guid userId, IEnumerable<Cipher> ciphers)
|
||||
{
|
||||
if(!ciphers.Any())
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using(var transaction = connection.BeginTransaction())
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -422,13 +422,13 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
INTO #TempCipher
|
||||
FROM [dbo].[Cipher]";
|
||||
|
||||
using(var cmd = new SqlCommand(sqlCreateTemp, connection, transaction))
|
||||
using (var cmd = new SqlCommand(sqlCreateTemp, connection, transaction))
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// 2. Bulk copy into temp tables.
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "#TempCipher";
|
||||
var dataTable = BuildCiphersTable(bulkCopy, ciphers);
|
||||
@ -458,7 +458,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
DROP TABLE #TempCipher";
|
||||
|
||||
using(var cmd = new SqlCommand(sql, connection, transaction))
|
||||
using (var cmd = new SqlCommand(sql, connection, transaction))
|
||||
{
|
||||
cmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = userId;
|
||||
cmd.ExecuteNonQuery();
|
||||
@ -482,22 +482,22 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders)
|
||||
{
|
||||
if(!ciphers.Any())
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using(var transaction = connection.BeginTransaction())
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(folders.Any())
|
||||
if (folders.Any())
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Folder]";
|
||||
var dataTable = BuildFoldersTable(bulkCopy, folders);
|
||||
@ -505,7 +505,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Cipher]";
|
||||
var dataTable = BuildCiphersTable(bulkCopy, ciphers);
|
||||
@ -531,38 +531,38 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections,
|
||||
IEnumerable<CollectionCipher> collectionCiphers)
|
||||
{
|
||||
if(!ciphers.Any())
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using(var transaction = connection.BeginTransaction())
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Cipher]";
|
||||
var dataTable = BuildCiphersTable(bulkCopy, ciphers);
|
||||
bulkCopy.WriteToServer(dataTable);
|
||||
}
|
||||
|
||||
if(collections.Any())
|
||||
if (collections.Any())
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Collection]";
|
||||
var dataTable = BuildCollectionsTable(bulkCopy, collections);
|
||||
bulkCopy.WriteToServer(dataTable);
|
||||
}
|
||||
|
||||
if(collectionCiphers.Any())
|
||||
if (collectionCiphers.Any())
|
||||
{
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, transaction))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[CollectionCipher]";
|
||||
var dataTable = BuildCollectionCiphersTable(bulkCopy, collectionCiphers);
|
||||
@ -590,7 +590,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
private DataTable BuildCiphersTable(SqlBulkCopy bulkCopy, IEnumerable<Cipher> ciphers)
|
||||
{
|
||||
var c = ciphers.FirstOrDefault();
|
||||
if(c == null)
|
||||
if (c == null)
|
||||
{
|
||||
throw new ApplicationException("Must have some ciphers to bulk import.");
|
||||
}
|
||||
@ -618,7 +618,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var revisionDateColumn = new DataColumn(nameof(c.RevisionDate), c.RevisionDate.GetType());
|
||||
ciphersTable.Columns.Add(revisionDateColumn);
|
||||
|
||||
foreach(DataColumn col in ciphersTable.Columns)
|
||||
foreach (DataColumn col in ciphersTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
|
||||
}
|
||||
@ -627,7 +627,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
keys[0] = idColumn;
|
||||
ciphersTable.PrimaryKey = keys;
|
||||
|
||||
foreach(var cipher in ciphers)
|
||||
foreach (var cipher in ciphers)
|
||||
{
|
||||
var row = ciphersTable.NewRow();
|
||||
|
||||
@ -651,7 +651,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
private DataTable BuildFoldersTable(SqlBulkCopy bulkCopy, IEnumerable<Folder> folders)
|
||||
{
|
||||
var f = folders.FirstOrDefault();
|
||||
if(f == null)
|
||||
if (f == null)
|
||||
{
|
||||
throw new ApplicationException("Must have some folders to bulk import.");
|
||||
}
|
||||
@ -669,7 +669,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var revisionDateColumn = new DataColumn(nameof(f.RevisionDate), f.RevisionDate.GetType());
|
||||
foldersTable.Columns.Add(revisionDateColumn);
|
||||
|
||||
foreach(DataColumn col in foldersTable.Columns)
|
||||
foreach (DataColumn col in foldersTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
|
||||
}
|
||||
@ -678,7 +678,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
keys[0] = idColumn;
|
||||
foldersTable.PrimaryKey = keys;
|
||||
|
||||
foreach(var folder in folders)
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
var row = foldersTable.NewRow();
|
||||
|
||||
@ -697,7 +697,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
private DataTable BuildCollectionsTable(SqlBulkCopy bulkCopy, IEnumerable<Collection> collections)
|
||||
{
|
||||
var c = collections.FirstOrDefault();
|
||||
if(c == null)
|
||||
if (c == null)
|
||||
{
|
||||
throw new ApplicationException("Must have some collections to bulk import.");
|
||||
}
|
||||
@ -715,7 +715,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var revisionDateColumn = new DataColumn(nameof(c.RevisionDate), c.RevisionDate.GetType());
|
||||
collectionsTable.Columns.Add(revisionDateColumn);
|
||||
|
||||
foreach(DataColumn col in collectionsTable.Columns)
|
||||
foreach (DataColumn col in collectionsTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
|
||||
}
|
||||
@ -724,7 +724,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
keys[0] = idColumn;
|
||||
collectionsTable.PrimaryKey = keys;
|
||||
|
||||
foreach(var collection in collections)
|
||||
foreach (var collection in collections)
|
||||
{
|
||||
var row = collectionsTable.NewRow();
|
||||
|
||||
@ -743,7 +743,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
private DataTable BuildCollectionCiphersTable(SqlBulkCopy bulkCopy, IEnumerable<CollectionCipher> collectionCiphers)
|
||||
{
|
||||
var cc = collectionCiphers.FirstOrDefault();
|
||||
if(cc == null)
|
||||
if (cc == null)
|
||||
{
|
||||
throw new ApplicationException("Must have some collectionCiphers to bulk import.");
|
||||
}
|
||||
@ -755,7 +755,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var cipherIdColumn = new DataColumn(nameof(cc.CipherId), cc.CipherId.GetType());
|
||||
collectionCiphersTable.Columns.Add(cipherIdColumn);
|
||||
|
||||
foreach(DataColumn col in collectionCiphersTable.Columns)
|
||||
foreach (DataColumn col in collectionCiphersTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
|
||||
}
|
||||
@ -765,7 +765,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
keys[1] = cipherIdColumn;
|
||||
collectionCiphersTable.PrimaryKey = keys;
|
||||
|
||||
foreach(var collectionCipher in collectionCiphers)
|
||||
foreach (var collectionCipher in collectionCiphers)
|
||||
{
|
||||
var row = collectionCiphersTable.NewRow();
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<CollectionCipher>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionCipher>(
|
||||
"[dbo].[CollectionCipher_ReadByUserId]",
|
||||
@ -35,7 +35,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<CollectionCipher>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionCipher>(
|
||||
"[dbo].[CollectionCipher_ReadByOrganizationId]",
|
||||
@ -48,7 +48,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<CollectionCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionCipher>(
|
||||
"[dbo].[CollectionCipher_ReadByUserIdCipherId]",
|
||||
@ -61,7 +61,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateCollectionsAsync(Guid cipherId, Guid userId, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[CollectionCipher_UpdateCollections]",
|
||||
@ -72,7 +72,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateCollectionsForAdminAsync(Guid cipherId, Guid organizationId, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[CollectionCipher_UpdateCollectionsAdmin]",
|
||||
@ -84,7 +84,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task UpdateCollectionsForCiphersAsync(IEnumerable<Guid> cipherIds, Guid userId,
|
||||
Guid organizationId, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[CollectionCipher_UpdateCollectionsForCiphers]",
|
||||
|
@ -24,7 +24,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<int> GetCountByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteScalarAsync<int>(
|
||||
"[dbo].[Collection_ReadCountByOrganizationId]",
|
||||
@ -37,7 +37,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<Tuple<Collection, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
$"[{Schema}].[Collection_ReadWithGroupsById]",
|
||||
@ -54,7 +54,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task<Tuple<CollectionDetails, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(
|
||||
Guid id, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
$"[{Schema}].[Collection_ReadWithGroupsByIdUserId]",
|
||||
@ -70,7 +70,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Collection>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Collection>(
|
||||
$"[{Schema}].[{Table}_ReadByOrganizationId]",
|
||||
@ -83,7 +83,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<CollectionDetails> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionDetails>(
|
||||
$"[{Schema}].[Collection_ReadByIdUserId]",
|
||||
@ -96,7 +96,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionDetails>(
|
||||
$"[{Schema}].[Collection_ReadByUserId]",
|
||||
@ -117,7 +117,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithGroups = JsonConvert.DeserializeObject<CollectionWithGroups>(JsonConvert.SerializeObject(obj));
|
||||
objWithGroups.Groups = groups.ToArrayTVP();
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Collection_CreateWithGroups]",
|
||||
@ -131,7 +131,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithGroups = JsonConvert.DeserializeObject<CollectionWithGroups>(JsonConvert.SerializeObject(obj));
|
||||
objWithGroups.Groups = groups.ToArrayTVP();
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Collection_UpdateWithGroups]",
|
||||
@ -142,7 +142,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task CreateUserAsync(Guid collectionId, Guid organizationUserId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CollectionUser_Create]",
|
||||
@ -153,7 +153,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteUserAsync(Guid collectionId, Guid organizationUserId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CollectionUser_Delete]",
|
||||
@ -164,7 +164,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateUsersAsync(Guid id, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CollectionUser_UpdateUsers]",
|
||||
@ -175,7 +175,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<SelectionReadOnly>> GetManyUsersByIdAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<SelectionReadOnly>(
|
||||
$"[{Schema}].[CollectionUser_ReadByCollectionId]",
|
||||
|
@ -22,7 +22,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task<Device> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
var device = await GetByIdAsync(id);
|
||||
if(device == null || device.UserId != userId)
|
||||
if (device == null || device.UserId != userId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<Device> GetByIdentifierAsync(string identifier)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Device>(
|
||||
$"[{Schema}].[{Table}_ReadByIdentifier]",
|
||||
@ -48,7 +48,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<Device> GetByIdentifierAsync(string identifier, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Device>(
|
||||
$"[{Schema}].[{Table}_ReadByIdentifierUserId]",
|
||||
@ -65,7 +65,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Device>(
|
||||
$"[{Schema}].[{Table}_ReadByUserId]",
|
||||
@ -78,7 +78,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task ClearPushTokenAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
$"[{Schema}].[{Table}_ClearPushTokenById]",
|
||||
|
@ -65,7 +65,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task CreateAsync(IEvent e)
|
||||
{
|
||||
if(!(e is Event ev))
|
||||
if (!(e is Event ev))
|
||||
{
|
||||
ev = new Event(e);
|
||||
}
|
||||
@ -75,21 +75,21 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task CreateManyAsync(IList<IEvent> entities)
|
||||
{
|
||||
if(!entities?.Any() ?? true)
|
||||
if (!entities?.Any() ?? true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(entities.Count == 1)
|
||||
if (entities.Count == 1)
|
||||
{
|
||||
await CreateAsync(entities.First());
|
||||
return;
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
using(var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, null))
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, null))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Event]";
|
||||
var dataTable = BuildEventsTable(bulkCopy, entities.Select(e => e is Event ? e as Event : new Event(e)));
|
||||
@ -102,7 +102,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
IDictionary<string, object> sprocParams, DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
DateTime? beforeDate = null;
|
||||
if(!string.IsNullOrWhiteSpace(pageOptions.ContinuationToken) &&
|
||||
if (!string.IsNullOrWhiteSpace(pageOptions.ContinuationToken) &&
|
||||
long.TryParse(pageOptions.ContinuationToken, out var binaryDate))
|
||||
{
|
||||
beforeDate = DateTime.SpecifyKind(DateTime.FromBinary(binaryDate), DateTimeKind.Utc);
|
||||
@ -116,13 +116,13 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
parameters.Add("@EndDate", endDate.ToUniversalTime(), DbType.DateTime2, null, 7);
|
||||
parameters.Add("@BeforeDate", beforeDate, DbType.DateTime2, null, 7);
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var events = (await connection.QueryAsync<Event>(sprocName, parameters,
|
||||
commandType: CommandType.StoredProcedure)).ToList();
|
||||
|
||||
var result = new PagedResult<IEvent>();
|
||||
if(events.Any() && events.Count >= pageOptions.PageSize)
|
||||
if (events.Any() && events.Count >= pageOptions.PageSize)
|
||||
{
|
||||
result.ContinuationToken = events.Last().Date.ToBinary().ToString();
|
||||
}
|
||||
@ -134,7 +134,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
private DataTable BuildEventsTable(SqlBulkCopy bulkCopy, IEnumerable<Event> events)
|
||||
{
|
||||
var e = events.FirstOrDefault();
|
||||
if(e == null)
|
||||
if (e == null)
|
||||
{
|
||||
throw new ApplicationException("Must have some events to bulk import.");
|
||||
}
|
||||
@ -168,7 +168,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var dateColumn = new DataColumn(nameof(e.Date), e.Date.GetType());
|
||||
eventsTable.Columns.Add(dateColumn);
|
||||
|
||||
foreach(DataColumn col in eventsTable.Columns)
|
||||
foreach (DataColumn col in eventsTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
|
||||
}
|
||||
@ -177,7 +177,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
keys[0] = idColumn;
|
||||
eventsTable.PrimaryKey = keys;
|
||||
|
||||
foreach(var ev in events)
|
||||
foreach (var ev in events)
|
||||
{
|
||||
ev.SetNewId();
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public async Task<Folder> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
var folder = await GetByIdAsync(id);
|
||||
if(folder == null || folder.UserId != userId)
|
||||
if (folder == null || folder.UserId != userId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Folder>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Folder>(
|
||||
$"[{Schema}].[Folder_ReadByUserId]",
|
||||
|
@ -21,7 +21,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<Grant> GetByKeyAsync(string key)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Grant>(
|
||||
"[dbo].[Grant_ReadByKey]",
|
||||
@ -34,7 +34,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Grant>> GetManyAsync(string subjectId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Grant>(
|
||||
"[dbo].[Grant_ReadBySubjectId]",
|
||||
@ -47,7 +47,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task SaveAsync(Grant obj)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[Grant_Save]",
|
||||
@ -58,7 +58,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAsync(string key)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"[dbo].[Grant_DeleteByKey]",
|
||||
@ -69,7 +69,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAsync(string subjectId, string clientId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"[dbo].[Grant_DeleteBySubjectIdClientId]",
|
||||
@ -80,7 +80,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteAsync(string subjectId, string clientId, string type)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"[dbo].[Grant_DeleteBySubjectIdClientIdType]",
|
||||
|
@ -24,7 +24,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<Tuple<Group, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
$"[{Schema}].[Group_ReadWithCollectionsById]",
|
||||
@ -40,7 +40,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Group>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Group>(
|
||||
$"[{Schema}].[Group_ReadByOrganizationId]",
|
||||
@ -53,7 +53,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Guid>(
|
||||
$"[{Schema}].[GroupUser_ReadGroupIdsByOrganizationUserId]",
|
||||
@ -66,7 +66,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<Guid>> GetManyUserIdsByIdAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Guid>(
|
||||
$"[{Schema}].[GroupUser_ReadOrganizationUserIdsByGroupId]",
|
||||
@ -79,7 +79,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task<ICollection<GroupUser>> GetManyGroupUsersByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<GroupUser>(
|
||||
$"[{Schema}].[GroupUser_ReadByOrganizationId]",
|
||||
@ -96,7 +96,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithCollections = JsonConvert.DeserializeObject<GroupWithCollections>(JsonConvert.SerializeObject(obj));
|
||||
objWithCollections.Collections = collections.ToArrayTVP();
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Group_CreateWithCollections]",
|
||||
@ -110,7 +110,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
var objWithCollections = JsonConvert.DeserializeObject<GroupWithCollections>(JsonConvert.SerializeObject(obj));
|
||||
objWithCollections.Collections = collections.ToArrayTVP();
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Group_UpdateWithCollections]",
|
||||
@ -121,7 +121,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task DeleteUserAsync(Guid groupId, Guid organizationUserId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[GroupUser_Delete]",
|
||||
@ -132,7 +132,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
|
||||
public async Task UpdateUsersAsync(Guid groupId, IEnumerable<Guid> organizationUserIds)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[GroupUser_UpdateUsers]",
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user