From 6b996e3a98fa74dc379b59deaf8d99dbd5d6d1f6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 7 Jul 2016 00:27:29 -0400 Subject: [PATCH] Generate password cell added to add/edit site pages. Delete callback from generate password page. --- .../Pages/Tools/ToolsPasswordGeneratorPage.cs | 26 ++++++------ src/App/Pages/Vault/VaultAddSitePage.cs | 35 ++++++++++++---- src/App/Pages/Vault/VaultEditSitePage.cs | 42 +++++++++++++++---- 3 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs b/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs index 78f5c78a9..d4b950a29 100644 --- a/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs +++ b/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs @@ -16,13 +16,15 @@ namespace Bit.App.Pages private readonly IPasswordGenerationService _passwordGenerationService; private readonly ISettings _settings; private readonly IClipboardService _clipboardService; + private readonly Action _passwordValueAction; - public ToolsPasswordGeneratorPage() + public ToolsPasswordGeneratorPage(Action passwordValueAction = null) { _userDialogs = Resolver.Resolve(); _passwordGenerationService = Resolver.Resolve(); _settings = Resolver.Resolve(); _clipboardService = Resolver.Resolve(); + _passwordValueAction = passwordValueAction; Init(); } @@ -57,8 +59,6 @@ namespace Bit.App.Pages regenerateCell.Tapped += RegenerateCell_Tapped; ; var copyCell = new ExtendedTextCell { Text = "Copy Password", TextColor = buttonColor }; copyCell.Tapped += CopyCell_Tapped; - var saveCell = new ExtendedTextCell { Text = "Save Password", TextColor = buttonColor }; - saveCell.Tapped += SaveCell_Tapped; var table = new ExtendedTableView { @@ -78,10 +78,6 @@ namespace Bit.App.Pages { regenerateCell, copyCell - }, - new TableSection - { - saveCell } } }; @@ -90,7 +86,7 @@ namespace Bit.App.Pages { table.RowHeight = -1; table.EstimatedRowHeight = 44; - ToolbarItems.Add(new DismissModalToolBarItem(this, "Close")); + ToolbarItems.Add(new DismissModalToolBarItem(this, _passwordValueAction == null ? "Close" : "Cancel")); } var stackLayout = new StackLayout @@ -108,6 +104,15 @@ namespace Bit.App.Pages VerticalOptions = LayoutOptions.FillAndExpand }; + var selectToolBarItem = new ToolbarItem("Select", null, async () => + { + _passwordValueAction(Password.Text); + await Navigation.PopModalAsync(); + }, ToolbarItemOrder.Default, 0); + + + ToolbarItems.Add(selectToolBarItem); + Title = "Generate Password"; Content = scrollView; BindingContext = Model; @@ -130,11 +135,6 @@ namespace Bit.App.Pages Model.Password = _passwordGenerationService.GeneratePassword(); } - private void SaveCell_Tapped(object sender, EventArgs e) - { - - } - private void CopyCell_Tapped(object sender, EventArgs e) { CopyPassword(); diff --git a/src/App/Pages/Vault/VaultAddSitePage.cs b/src/App/Pages/Vault/VaultAddSitePage.cs index a3b1a21fb..fdc620439 100644 --- a/src/App/Pages/Vault/VaultAddSitePage.cs +++ b/src/App/Pages/Vault/VaultAddSitePage.cs @@ -29,15 +29,17 @@ namespace Bit.App.Pages Init(); } + public FormEntryCell PasswordCell { get; private set; } + private void Init() { var notesCell = new FormEditorCell(height: 90); - var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); - var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry); + PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); + var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry); usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.Autocorrect = false; - usernameCell.Entry.FontFamily = passwordCell.Entry.FontFamily = "Courier"; + usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier"; var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry); var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry); @@ -50,6 +52,13 @@ namespace Bit.App.Pages } var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); + var generateCell = new ExtendedTextCell + { + Text = "Generate Password", + ShowDisclousure = true + }; + generateCell.Tapped += GenerateCell_Tapped; ; + var favoriteCell = new ExtendedSwitchCell { Text = "Favorite" }; var table = new ExtendedTableView @@ -57,7 +66,6 @@ namespace Bit.App.Pages Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, - EnableSelection = false, Root = new TableRoot { new TableSection("Site Information") @@ -65,11 +73,12 @@ namespace Bit.App.Pages nameCell, uriCell, usernameCell, - passwordCell, - folderCell + PasswordCell, + generateCell }, new TableSection { + folderCell, favoriteCell }, new TableSection(AppResources.Notes) @@ -93,7 +102,7 @@ namespace Bit.App.Pages return; } - if(string.IsNullOrWhiteSpace(passwordCell.Entry.Text)) + if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); return; @@ -110,7 +119,7 @@ namespace Bit.App.Pages Uri = uriCell.Entry.Text?.Encrypt(), Name = nameCell.Entry.Text?.Encrypt(), Username = usernameCell.Entry.Text?.Encrypt(), - Password = passwordCell.Entry.Text?.Encrypt(), + Password = PasswordCell.Entry.Text?.Encrypt(), Notes = notesCell.Editor.Text?.Encrypt(), Favorite = favoriteCell.On }; @@ -143,6 +152,16 @@ namespace Bit.App.Pages } } + private void GenerateCell_Tapped(object sender, EventArgs e) + { + var page = new ToolsPasswordGeneratorPage((password) => + { + PasswordCell.Entry.Text = password; + _userDialogs.SuccessToast("Password generated."); + }); + Navigation.PushModalAsync(new ExtendedNavigationPage(page)); + } + private void AlertNoConnection() { DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); diff --git a/src/App/Pages/Vault/VaultEditSitePage.cs b/src/App/Pages/Vault/VaultEditSitePage.cs index e13ed9099..5e8236906 100644 --- a/src/App/Pages/Vault/VaultEditSitePage.cs +++ b/src/App/Pages/Vault/VaultEditSitePage.cs @@ -30,6 +30,8 @@ namespace Bit.App.Pages Init(); } + public FormEntryCell PasswordCell { get; private set; } + private void Init() { var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult(); @@ -41,20 +43,27 @@ namespace Bit.App.Pages var notesCell = new FormEditorCell(height: 90); notesCell.Editor.Text = site.Notes?.Decrypt(); - var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); - passwordCell.Entry.Text = site.Password?.Decrypt(); - var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry); + PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); + PasswordCell.Entry.Text = site.Password?.Decrypt(); + var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry); usernameCell.Entry.Text = site.Username?.Decrypt(); usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.Autocorrect = false; - usernameCell.Entry.FontFamily = passwordCell.Entry.FontFamily = "Courier"; + usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier"; var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry); uriCell.Entry.Text = site.Uri?.Decrypt(); var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry); nameCell.Entry.Text = site.Name?.Decrypt(); + var generateCell = new ExtendedTextCell + { + Text = "Generate Password", + ShowDisclousure = true + }; + generateCell.Tapped += GenerateCell_Tapped; ; + var folderOptions = new List { AppResources.FolderNone }; var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt()); int selectedIndex = 0; @@ -93,11 +102,12 @@ namespace Bit.App.Pages nameCell, uriCell, usernameCell, - passwordCell, - folderCell + PasswordCell, + generateCell }, new TableSection { + folderCell, favoriteCell }, new TableSection(AppResources.Notes) @@ -125,7 +135,7 @@ namespace Bit.App.Pages return; } - if(string.IsNullOrWhiteSpace(passwordCell.Entry.Text)) + if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); return; @@ -140,7 +150,7 @@ namespace Bit.App.Pages site.Uri = uriCell.Entry.Text?.Encrypt(); site.Name = nameCell.Entry.Text?.Encrypt(); site.Username = usernameCell.Entry.Text?.Encrypt(); - site.Password = passwordCell.Entry.Text?.Encrypt(); + site.Password = PasswordCell.Entry.Text?.Encrypt(); site.Notes = notesCell.Editor.Text?.Encrypt(); site.Favorite = favoriteCell.On; @@ -176,6 +186,22 @@ namespace Bit.App.Pages } } + private async void GenerateCell_Tapped(object sender, EventArgs e) + { + if(!string.IsNullOrWhiteSpace(PasswordCell.Entry.Text) + && !await _userDialogs.ConfirmAsync("Are you sure you want to overwrite the current password?", null, AppResources.Yes, AppResources.No)) + { + return; + } + + var page = new ToolsPasswordGeneratorPage((password) => + { + PasswordCell.Entry.Text = password; + _userDialogs.SuccessToast("Password generated."); + }); + await Navigation.PushModalAsync(new ExtendedNavigationPage(page)); + } + private async void DeleteCell_Tapped(object sender, EventArgs e) { if(!_connectivity.IsConnected)