public async Task <ListResponseModel <SendResponseModel> > Get() { var userId = _userService.GetProperUserId(User).Value; var sends = await _sendRepository.GetManyByUserIdAsync(userId); var responses = sends.Select(s => new SendResponseModel(s, _globalSettings)); return(new ListResponseModel <SendResponseModel>(responses)); }
public async Task <SyncResponseModel> Get([FromQuery] bool excludeDomains = false) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) { throw new BadRequestException("User not found."); } var organizationUserDetails = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id, OrganizationUserStatusType.Confirmed); var providerUserDetails = await _providerUserRepository.GetManyDetailsByUserAsync(user.Id, ProviderUserStatusType.Confirmed); var providerUserOrganizationDetails = await _providerUserRepository.GetManyOrganizationDetailsByUserAsync(user.Id, ProviderUserStatusType.Confirmed); var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); var folders = await _folderRepository.GetManyByUserIdAsync(user.Id); var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, hasEnabledOrgs); var sends = await _sendRepository.GetManyByUserIdAsync(user.Id); IEnumerable <CollectionDetails> collections = null; IDictionary <Guid, IGrouping <Guid, CollectionCipher> > collectionCiphersGroupDict = null; IEnumerable <Policy> policies = null; if (hasEnabledOrgs) { collections = await _collectionRepository.GetManyByUserIdAsync(user.Id); var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id); collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key); policies = await _policyRepository.GetManyByUserIdAsync(user.Id); } var userTwoFactorEnabled = await _userService.TwoFactorIsEnabledAsync(user); var userHasPremiumFromOrganization = await _userService.HasPremiumFromOrganization(user); var response = new SyncResponseModel(_globalSettings, user, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationUserDetails, providerUserDetails, providerUserOrganizationDetails, folders, collections, ciphers, collectionCiphersGroupDict, excludeDomains, policies, sends); return(response); }
public async Task PostKey([FromBody] UpdateKeyRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) { throw new UnauthorizedAccessException(); } var ciphers = new List <Cipher>(); if (model.Ciphers.Any()) { var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id); ciphers.AddRange(existingCiphers .Join(model.Ciphers, c => c.Id, c => c.Id, (existing, c) => c.ToCipher(existing))); } var folders = new List <Folder>(); if (model.Folders.Any()) { var existingFolders = await _folderRepository.GetManyByUserIdAsync(user.Id); folders.AddRange(existingFolders .Join(model.Folders, f => f.Id, f => f.Id, (existing, f) => f.ToFolder(existing))); } var sends = new List <Send>(); if (model.Sends?.Any() == true) { var existingSends = await _sendRepository.GetManyByUserIdAsync(user.Id); sends.AddRange(existingSends .Join(model.Sends, s => s.Id, s => s.Id, (existing, s) => s.ToSend(existing, _sendService))); } var result = await _userService.UpdateKeyAsync( user, model.MasterPasswordHash, model.Key, model.PrivateKey, ciphers, folders, sends); if (result.Succeeded) { return; } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } await Task.Delay(2000); throw new BadRequestException(ModelState); }