1
0
mirror of https://github.com/bitwarden/mobile.git synced 2025-01-02 18:07:56 +01:00

moved password lock page to a table form

This commit is contained in:
Kyle Spearrin 2016-07-18 19:37:25 -04:00
parent d82c0d7d71
commit 299411e9a5
2 changed files with 6244 additions and 99 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,6 @@ using Bit.App.Abstractions;
using Bit.App.Resources; using Bit.App.Resources;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using Bit.App.Models.Page;
using Bit.App.Controls; using Bit.App.Controls;
using System.Linq; using System.Linq;
@ -16,7 +14,6 @@ namespace Bit.App.Pages
{ {
private readonly IAuthService _authService; private readonly IAuthService _authService;
private readonly IUserDialogs _userDialogs; private readonly IUserDialogs _userDialogs;
private readonly ISettings _settings;
private readonly ICryptoService _cryptoService; private readonly ICryptoService _cryptoService;
public LockPasswordPage() public LockPasswordPage()
@ -24,22 +21,36 @@ namespace Bit.App.Pages
{ {
_authService = Resolver.Resolve<IAuthService>(); _authService = Resolver.Resolve<IAuthService>();
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_settings = Resolver.Resolve<ISettings>();
_cryptoService = Resolver.Resolve<ICryptoService>(); _cryptoService = Resolver.Resolve<ICryptoService>();
Init(); Init();
} }
public Entry Password { get; private set; } public FormEntryCell PasswordCell { get; set; }
public void Init() public void Init()
{ {
Password = new ExtendedEntry PasswordCell = new FormEntryCell(AppResources.MasterPassword, IsPassword: true,
useLabelAsPlaceholder: true, imageSource: "lock");
PasswordCell.Entry.ReturnType = Enums.ReturnType.Go;
PasswordCell.Entry.Completed += Entry_Completed;
var table = new ExtendedTableView
{ {
HasBorder = false, Intent = TableIntent.Settings,
IsPassword = true, EnableScrolling = false,
Placeholder = AppResources.MasterPassword, HasUnevenRows = true,
ReturnType = Enums.ReturnType.Go EnableSelection = false,
VerticalOptions = LayoutOptions.Start,
NoFooter = true,
Root = new TableRoot
{
new TableSection()
{
PasswordCell
}
}
}; };
var logoutButton = new Button var logoutButton = new Button
@ -52,9 +63,8 @@ namespace Bit.App.Pages
var stackLayout = new StackLayout var stackLayout = new StackLayout
{ {
Padding = new Thickness(30, 40),
Spacing = 10, Spacing = 10,
Children = { Password, logoutButton } Children = { table, logoutButton }
}; };
var loginToolbarItem = new ToolbarItem("Submit", null, async () => var loginToolbarItem = new ToolbarItem("Submit", null, async () =>
@ -67,6 +77,11 @@ namespace Bit.App.Pages
Content = stackLayout; Content = stackLayout;
} }
private void Entry_Completed(object sender, EventArgs e)
{
var task = CheckPasswordAsync();
}
protected override bool OnBackButtonPressed() protected override bool OnBackButtonPressed()
{ {
return false; return false;
@ -75,18 +90,18 @@ namespace Bit.App.Pages
protected override void OnAppearing() protected override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
Password.Focus(); PasswordCell.Entry.Focus();
} }
protected async Task CheckPasswordAsync() protected async Task CheckPasswordAsync()
{ {
if(string.IsNullOrWhiteSpace(Password.Text)) if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{ {
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok); await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok);
return; return;
} }
var key = _cryptoService.MakeKeyFromPassword(Password.Text, _authService.Email); var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, _authService.Email);
if(key.SequenceEqual(_cryptoService.Key)) if(key.SequenceEqual(_cryptoService.Key))
{ {
await Navigation.PopModalAsync(); await Navigation.PopModalAsync();
@ -96,8 +111,8 @@ namespace Bit.App.Pages
// TODO: keep track of invalid attempts and logout? // TODO: keep track of invalid attempts and logout?
_userDialogs.Alert("Invalid Master Password. Try again."); _userDialogs.Alert("Invalid Master Password. Try again.");
Password.Text = string.Empty; PasswordCell.Entry.Text = string.Empty;
Password.Focus(); PasswordCell.Entry.Focus();
} }
} }