public async Task <FolderResponseModel> Post([FromBody] FolderRequestModel model) { var folder = model.ToCipher(_userService.GetProperUserId(User).Value); await _cipherService.SaveAsync(folder); return(new FolderResponseModel(folder)); }
public async Task <LoginResponseModel> Post([FromBody] LoginRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var login = model.ToCipherDetails(userId); await _cipherService.SaveAsync(login); var response = new LoginResponseModel(login); return(response); }
public async Task <LoginResponseModel> Post([FromBody] LoginRequestModel model, string[] expand = null) { var login = model.ToCipher(_userService.GetProperUserId(User).Value); await _cipherService.SaveAsync(login); var response = new LoginResponseModel(login); await ExpandAsync(login, response, expand, null); return(response); }
public async Task <SiteResponseModel> Post([FromBody] SiteRequestModel model, string[] expand = null) { var site = model.ToCipher(_userManager.GetUserId(User)); await _cipherService.SaveAsync(site); var response = new SiteResponseModel(site); await ExpandAsync(site, response, expand, null); return(response); }
public async Task <CipherMiniResponseModel> PostAdmin([FromBody] CipherRequestModel model) { var cipher = model.ToOrganizationCipher(); if (!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value)) { throw new NotFoundException(); } var userId = _userService.GetProperUserId(User).Value; await _cipherService.SaveAsync(cipher, userId, true); var response = new CipherMiniResponseModel(cipher, _globalSettings, false); return(response); }
public async Task <LoginResponseModel> PostAdmin([FromBody] LoginRequestModel model) { var login = model.ToOrganizationCipher(); if (!_currentContext.OrganizationAdmin(login.OrganizationId.Value)) { throw new NotFoundException(); } var userId = _userService.GetProperUserId(User).Value; await _cipherService.SaveAsync(login, userId, true); var response = new LoginResponseModel(login); return(response); }
public async Task <CipherMiniResponseModel> PostAdmin([FromBody] CipherCreateRequestModel model) { var cipher = model.Cipher.ToOrganizationCipher(); if (!await _currentContext.ManageAllCollections(cipher.OrganizationId.Value)) { throw new NotFoundException(); } var userId = _userService.GetProperUserId(User).Value; await _cipherService.SaveAsync(cipher, userId, model.Cipher.LastKnownRevisionDate, model.CollectionIds, true, false); var response = new CipherMiniResponseModel(cipher, _globalSettings, false); return(response); }
public async Task Favorite(string id) { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); if (cipher == null) { throw new NotFoundException(); } cipher.Favorite = !cipher.Favorite; await _cipherService.SaveAsync(cipher); }
private void Init() { FieldsSection = new TableSection(Helpers.GetEmptyTableSectionTitle()); Table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { FieldsSection } }; NoDataLabel = new Label { Text = AppResources.NoCustomFields, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(10, 40, 10, 0) }; SaveToolbarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), async() => { if (_lastAction.LastActionWasRecent() || _cipher == null) { return; } _lastAction = DateTime.UtcNow; if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (FieldsSection.Count > 0) { var fields = new List <Field>(); foreach (var cell in FieldsSection) { if (cell is FormEntryCell entryCell) { fields.Add(new Field { Name = string.IsNullOrWhiteSpace(entryCell.Label.Text) ? null : entryCell.Label.Text.Encrypt(_cipher.OrganizationId), Value = string.IsNullOrWhiteSpace(entryCell.Entry.Text) ? null : entryCell.Entry.Text.Encrypt(_cipher.OrganizationId), Type = entryCell.Entry.IsPassword ? FieldType.Hidden : FieldType.Text }); } else if (cell is ExtendedSwitchCell switchCell) { var value = switchCell.On ? "true" : "false"; fields.Add(new Field { Name = string.IsNullOrWhiteSpace(switchCell.Text) ? null : switchCell.Text.Encrypt(_cipher.OrganizationId), Value = value.Encrypt(_cipher.OrganizationId), Type = FieldType.Boolean }); } } _cipher.Fields = fields; } else { _cipher.Fields = null; } _deviceActionService.ShowLoading(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(_cipher); _deviceActionService.HideLoading(); if (saveTask.Succeeded) { _deviceActionService.Toast(AppResources.CustomFieldsUpdated); _googleAnalyticsService.TrackAppEvent("UpdatedCustomFields"); await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0);
private void InitSave() { var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() => { if (_lastAction.LastActionWasRecent()) { return; } _lastAction = DateTime.UtcNow; if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(NameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } Cipher.Name = NameCell.Entry.Text.Encrypt(Cipher.OrganizationId); Cipher.Notes = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(Cipher.OrganizationId); Cipher.Favorite = FavoriteCell.On; switch (Cipher.Type) { case CipherType.Login: Cipher.Login = new Login { Uri = string.IsNullOrWhiteSpace(LoginUriCell.Entry.Text) ? null : LoginUriCell.Entry.Text.Encrypt(Cipher.OrganizationId), Username = string.IsNullOrWhiteSpace(LoginUsernameCell.Entry.Text) ? null : LoginUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Password = string.IsNullOrWhiteSpace(LoginPasswordCell.Entry.Text) ? null : LoginPasswordCell.Entry.Text.Encrypt(Cipher.OrganizationId), Totp = string.IsNullOrWhiteSpace(LoginTotpCell.Entry.Text) ? null : LoginTotpCell.Entry.Text.Encrypt(Cipher.OrganizationId), }; break; case CipherType.SecureNote: Cipher.SecureNote = new SecureNote { Type = SecureNoteType.Generic }; break; case CipherType.Card: string brand; switch (CardBrandCell.Picker.SelectedIndex) { case 1: brand = "Visa"; break; case 2: brand = "Mastercard"; break; case 3: brand = "Amex"; break; case 4: brand = "Discover"; break; case 5: brand = "Diners Club"; break; case 6: brand = "JCB"; break; case 7: brand = "Maestro"; break; case 8: brand = "UnionPay"; break; case 9: brand = "Other"; break; default: brand = null; break; } var expMonth = CardExpMonthCell.Picker.SelectedIndex > 0 ? CardExpMonthCell.Picker.SelectedIndex.ToString() : null; Cipher.Card = new Card { CardholderName = string.IsNullOrWhiteSpace(CardNameCell.Entry.Text) ? null : CardNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Number = string.IsNullOrWhiteSpace(CardNumberCell.Entry.Text) ? null : CardNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), ExpYear = string.IsNullOrWhiteSpace(CardExpYearCell.Entry.Text) ? null : CardExpYearCell.Entry.Text.Encrypt(Cipher.OrganizationId), Code = string.IsNullOrWhiteSpace(CardCodeCell.Entry.Text) ? null : CardCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Brand = string.IsNullOrWhiteSpace(brand) ? null : brand.Encrypt(Cipher.OrganizationId), ExpMonth = string.IsNullOrWhiteSpace(expMonth) ? null : expMonth.Encrypt(Cipher.OrganizationId) }; break; case CipherType.Identity: string title; switch (IdTitleCell.Picker.SelectedIndex) { case 1: title = AppResources.Mr; break; case 2: title = AppResources.Mrs; break; case 3: title = AppResources.Ms; break; case 4: title = AppResources.Dr; break; default: title = null; break; } Cipher.Identity = new Identity { Title = string.IsNullOrWhiteSpace(title) ? null : title.Encrypt(Cipher.OrganizationId), FirstName = string.IsNullOrWhiteSpace(IdFirstNameCell.Entry.Text) ? null : IdFirstNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), MiddleName = string.IsNullOrWhiteSpace(IdMiddleNameCell.Entry.Text) ? null : IdMiddleNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), LastName = string.IsNullOrWhiteSpace(IdLastNameCell.Entry.Text) ? null : IdLastNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Username = string.IsNullOrWhiteSpace(IdUsernameCell.Entry.Text) ? null : IdUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Company = string.IsNullOrWhiteSpace(IdCompanyCell.Entry.Text) ? null : IdCompanyCell.Entry.Text.Encrypt(Cipher.OrganizationId), SSN = string.IsNullOrWhiteSpace(IdSsnCell.Entry.Text) ? null : IdSsnCell.Entry.Text.Encrypt(Cipher.OrganizationId), PassportNumber = string.IsNullOrWhiteSpace(IdPassportNumberCell.Entry.Text) ? null : IdPassportNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), LicenseNumber = string.IsNullOrWhiteSpace(IdLicenseNumberCell.Entry.Text) ? null : IdLicenseNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), Email = string.IsNullOrWhiteSpace(IdEmailCell.Entry.Text) ? null : IdEmailCell.Entry.Text.Encrypt(Cipher.OrganizationId), Phone = string.IsNullOrWhiteSpace(IdPhoneCell.Entry.Text) ? null : IdPhoneCell.Entry.Text.Encrypt(Cipher.OrganizationId), Address1 = string.IsNullOrWhiteSpace(IdAddress1Cell.Entry.Text) ? null : IdAddress1Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address2 = string.IsNullOrWhiteSpace(IdAddress2Cell.Entry.Text) ? null : IdAddress2Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address3 = string.IsNullOrWhiteSpace(IdAddress3Cell.Entry.Text) ? null : IdAddress3Cell.Entry.Text.Encrypt(Cipher.OrganizationId), City = string.IsNullOrWhiteSpace(IdCityCell.Entry.Text) ? null : IdCityCell.Entry.Text.Encrypt(Cipher.OrganizationId), State = string.IsNullOrWhiteSpace(IdStateCell.Entry.Text) ? null : IdStateCell.Entry.Text.Encrypt(Cipher.OrganizationId), PostalCode = string.IsNullOrWhiteSpace(IdPostalCodeCell.Entry.Text) ? null : IdPostalCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Country = string.IsNullOrWhiteSpace(IdCountryCell.Entry.Text) ? null : IdCountryCell.Entry.Text.Encrypt(Cipher.OrganizationId) }; break; default: break; } if (FolderCell.Picker.SelectedIndex > 0) { Cipher.FolderId = Folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id; } else { Cipher.FolderId = null; } _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black); var saveTask = await _cipherService.SaveAsync(Cipher); _userDialogs.HideLoading(); if (saveTask.Succeeded) { _userDialogs.Toast(AppResources.ItemUpdated); _googleAnalyticsService.TrackAppEvent("EditedCipher"); await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred); } else { await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); } }, ToolbarItemOrder.Default, 0); ToolbarItems.Add(saveToolBarItem); }
private async void CipherSelected(object sender, SelectedItemChangedEventArgs e) { var cipher = e.SelectedItem as Cipher; if (cipher == null) { return; } string selection = null; if (!string.IsNullOrWhiteSpace(_uri)) { var options = new List <string> { AppResources.Autofill }; if (cipher.Type == Enums.CipherType.Login && _connectivity.IsConnected) { options.Add(AppResources.AutofillAndSave); } options.Add(AppResources.View); selection = await DisplayActionSheet(AppResources.AutofillOrView, AppResources.Cancel, null, options.ToArray()); } if (selection == AppResources.View || string.IsNullOrWhiteSpace(_uri)) { var page = new VaultViewCipherPage(cipher.Type, cipher.Id); await Navigation.PushForDeviceAsync(page); } else if (selection == AppResources.Autofill || selection == AppResources.AutofillAndSave) { if (selection == AppResources.AutofillAndSave) { if (!_connectivity.IsConnected) { Helpers.AlertNoConnection(this); } else { var uris = cipher.CipherModel.Login?.Uris?.ToList(); if (uris == null) { uris = new List <Models.LoginUri>(); } uris.Add(new Models.LoginUri { Uri = _uri.Encrypt(cipher.CipherModel.OrganizationId), Match = null }); cipher.CipherModel.Login.Uris = uris; await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(cipher.CipherModel); await _deviceActionService.HideLoadingAsync(); if (saveTask.Succeeded) { _googleAnalyticsService.TrackAppEvent("AddedLoginUriDuringAutofill"); } } } if (_deviceInfoService.Version < 21) { Helpers.CipherMoreClickedAsync(this, cipher, !string.IsNullOrWhiteSpace(_uri)); } else { _googleAnalyticsService.TrackExtensionEvent("AutoFilled", _uri.StartsWith("http") ? "Website" : "App"); _deviceActionService.Autofill(cipher); } } ((ListView)sender).SelectedItem = null; }
private void InitSave() { var saveToolBarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("save.png"), async() => { if (_lastAction.LastActionWasRecent()) { return; } _lastAction = DateTime.UtcNow; if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(NameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } Cipher.Name = NameCell.Entry.Text.Encrypt(Cipher.OrganizationId); Cipher.Notes = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(Cipher.OrganizationId); Cipher.Favorite = FavoriteCell.On; var passwordHistory = Cipher.PasswordHistory?.ToList() ?? new List <PasswordHistory>(); switch (Cipher.Type) { case CipherType.Login: Cipher.Login = new Login { Username = string.IsNullOrWhiteSpace(LoginUsernameCell.Entry.Text) ? null : LoginUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Password = string.IsNullOrWhiteSpace(LoginPasswordCell.Entry.Text) ? null : LoginPasswordCell.Entry.Text.Encrypt(Cipher.OrganizationId), Totp = string.IsNullOrWhiteSpace(LoginTotpCell.Entry.Text) ? null : LoginTotpCell.Entry.Text.Encrypt(Cipher.OrganizationId), PasswordRevisionDate = Cipher.Login.PasswordRevisionDate, }; if (!string.IsNullOrWhiteSpace(_originalLoginPassword) && LoginPasswordCell.Entry.Text != _originalLoginPassword) { var now = DateTime.UtcNow; passwordHistory.Insert(0, new PasswordHistory { LastUsedDate = now, Password = _originalLoginPassword.Encrypt(Cipher.OrganizationId), }); Cipher.Login.PasswordRevisionDate = now; } Helpers.ProcessUrisSectionForSave(UrisSection, Cipher); break; case CipherType.SecureNote: Cipher.SecureNote = new SecureNote { Type = SecureNoteType.Generic }; break; case CipherType.Card: string brand; switch (CardBrandCell.Picker.SelectedIndex) { case 1: brand = "Visa"; break; case 2: brand = "Mastercard"; break; case 3: brand = "Amex"; break; case 4: brand = "Discover"; break; case 5: brand = "Diners Club"; break; case 6: brand = "JCB"; break; case 7: brand = "Maestro"; break; case 8: brand = "UnionPay"; break; case 9: brand = "Other"; break; default: brand = null; break; } var expMonth = CardExpMonthCell.Picker.SelectedIndex > 0 ? CardExpMonthCell.Picker.SelectedIndex.ToString() : null; Cipher.Card = new Card { CardholderName = string.IsNullOrWhiteSpace(CardNameCell.Entry.Text) ? null : CardNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Number = string.IsNullOrWhiteSpace(CardNumberCell.Entry.Text) ? null : CardNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), ExpYear = string.IsNullOrWhiteSpace(CardExpYearCell.Entry.Text) ? null : CardExpYearCell.Entry.Text.Encrypt(Cipher.OrganizationId), Code = string.IsNullOrWhiteSpace(CardCodeCell.Entry.Text) ? null : CardCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Brand = string.IsNullOrWhiteSpace(brand) ? null : brand.Encrypt(Cipher.OrganizationId), ExpMonth = string.IsNullOrWhiteSpace(expMonth) ? null : expMonth.Encrypt(Cipher.OrganizationId) }; break; case CipherType.Identity: string title; switch (IdTitleCell.Picker.SelectedIndex) { case 1: title = AppResources.Mr; break; case 2: title = AppResources.Mrs; break; case 3: title = AppResources.Ms; break; case 4: title = AppResources.Dr; break; default: title = null; break; } Cipher.Identity = new Identity { Title = string.IsNullOrWhiteSpace(title) ? null : title.Encrypt(Cipher.OrganizationId), FirstName = string.IsNullOrWhiteSpace(IdFirstNameCell.Entry.Text) ? null : IdFirstNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), MiddleName = string.IsNullOrWhiteSpace(IdMiddleNameCell.Entry.Text) ? null : IdMiddleNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), LastName = string.IsNullOrWhiteSpace(IdLastNameCell.Entry.Text) ? null : IdLastNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Username = string.IsNullOrWhiteSpace(IdUsernameCell.Entry.Text) ? null : IdUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Company = string.IsNullOrWhiteSpace(IdCompanyCell.Entry.Text) ? null : IdCompanyCell.Entry.Text.Encrypt(Cipher.OrganizationId), SSN = string.IsNullOrWhiteSpace(IdSsnCell.Entry.Text) ? null : IdSsnCell.Entry.Text.Encrypt(Cipher.OrganizationId), PassportNumber = string.IsNullOrWhiteSpace(IdPassportNumberCell.Entry.Text) ? null : IdPassportNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), LicenseNumber = string.IsNullOrWhiteSpace(IdLicenseNumberCell.Entry.Text) ? null : IdLicenseNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), Email = string.IsNullOrWhiteSpace(IdEmailCell.Entry.Text) ? null : IdEmailCell.Entry.Text.Encrypt(Cipher.OrganizationId), Phone = string.IsNullOrWhiteSpace(IdPhoneCell.Entry.Text) ? null : IdPhoneCell.Entry.Text.Encrypt(Cipher.OrganizationId), Address1 = string.IsNullOrWhiteSpace(IdAddress1Cell.Entry.Text) ? null : IdAddress1Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address2 = string.IsNullOrWhiteSpace(IdAddress2Cell.Entry.Text) ? null : IdAddress2Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address3 = string.IsNullOrWhiteSpace(IdAddress3Cell.Entry.Text) ? null : IdAddress3Cell.Entry.Text.Encrypt(Cipher.OrganizationId), City = string.IsNullOrWhiteSpace(IdCityCell.Entry.Text) ? null : IdCityCell.Entry.Text.Encrypt(Cipher.OrganizationId), State = string.IsNullOrWhiteSpace(IdStateCell.Entry.Text) ? null : IdStateCell.Entry.Text.Encrypt(Cipher.OrganizationId), PostalCode = string.IsNullOrWhiteSpace(IdPostalCodeCell.Entry.Text) ? null : IdPostalCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Country = string.IsNullOrWhiteSpace(IdCountryCell.Entry.Text) ? null : IdCountryCell.Entry.Text.Encrypt(Cipher.OrganizationId) }; break; default: break; } if (FolderCell.Picker.SelectedIndex > 0) { Cipher.FolderId = Folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id; } else { Cipher.FolderId = null; } var hiddenFields = Helpers.ProcessFieldsSectionForSave(FieldsSection, Cipher); var changedFields = _originalHiddenFields.Where(of => hiddenFields.Any(f => f.Item1 == of.Item1 && f.Item2 != of.Item2)); foreach (var cf in changedFields) { passwordHistory.Insert(0, new PasswordHistory { LastUsedDate = DateTime.UtcNow, Password = (cf.Item1 + ": " + cf.Item2).Encrypt(Cipher.OrganizationId), }); } Cipher.PasswordHistory = (passwordHistory?.Count ?? 0) > 0 ? passwordHistory.Take(5) : null; await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(Cipher); await _deviceActionService.HideLoadingAsync(); if (saveTask.Succeeded) { _deviceActionService.Toast(AppResources.ItemUpdated); _googleAnalyticsService.TrackAppEvent("EditedCipher"); await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0); ToolbarItems.Add(saveToolBarItem); }