Login page updates

This commit is contained in:
Kyle Spearrin 2016-06-23 23:03:00 -04:00
parent a437731bfa
commit 3532037700
8 changed files with 2887 additions and 3110 deletions

File diff suppressed because it is too large Load diff

View file

@ -189,6 +189,16 @@ namespace Bit.App
}
});
Resources.Add("btn-white", new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.BackgroundColorProperty, Value = Color.White },
new Setter { Property = Button.TextColorProperty, Value = primaryColor },
new Setter { Property = Button.FontAttributesProperty, Value = FontAttributes.Bold },
new Setter { Property = Button.BorderRadiusProperty, Value = 0 }
}
});
Resources.Add(new Style(typeof(Button))
{
Setters = {

View file

@ -93,7 +93,6 @@
<Compile Include="Pages\HomePage.cs" />
<Compile Include="Pages\SettingsPinPage.cs" />
<Compile Include="Pages\LockPinPage.cs" />
<Compile Include="Pages\LoginNavigationPage.cs" />
<Compile Include="Pages\MainPage.cs" />
<Compile Include="Pages\SettingsEditFolderPage.cs" />
<Compile Include="Pages\LockFingerprintPage.cs" />

View file

@ -6,6 +6,7 @@ using Bit.App.Resources;
using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using Bit.App.Controls;
namespace Bit.App.Pages
{
@ -36,15 +37,18 @@ namespace Bit.App.Pages
var message = new Label
{
Text = "Welcome!",
Text = "Log in or create a new account to access your secure vault.",
VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.Center
HorizontalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center,
LineBreakMode = LineBreakMode.WordWrap,
FontSize = 20
};
var createAccountButton = new Button
{
Text = "Create Account",
//Command = new Command(async () => await LogoutAsync()),
//Command = new Command(async () => await RegisterAsync()),
VerticalOptions = LayoutOptions.End,
HorizontalOptions = LayoutOptions.Fill,
Style = (Style)Application.Current.Resources["btn-primary"],
@ -75,7 +79,7 @@ namespace Bit.App.Pages
public async Task LoginAsync()
{
await Navigation.PushModalAsync(new LoginNavigationPage());
await Navigation.PushModalAsync(new ExtendedNavigationPage(new LoginPage()));
}
}
}

View file

@ -1,16 +0,0 @@
using Bit.App.Resources;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class LoginNavigationPage : NavigationPage
{
public LoginNavigationPage()
: base(new LoginPage())
{
BarBackgroundColor = Color.Transparent;
BarTextColor = Color.FromHex("333333");
Title = AppResources.LogInNoun;
}
}
}

View file

@ -1,102 +1,129 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Bit.App.Abstractions;
using Bit.App.Behaviors;
using Bit.App.Controls;
using Bit.App.Models.Api;
using Bit.App.Resources;
using Plugin.DeviceInfo.Abstractions;
using Xamarin.Forms;
using XLabs.Ioc;
using Acr.UserDialogs;
using System.Threading.Tasks;
namespace Bit.App.Pages
{
public class LoginPage : ContentPage
{
private ICryptoService _cryptoService;
private IAuthService _authService;
private IDeviceInfo _deviceInfo;
private IAppIdService _appIdService;
private IUserDialogs _userDialogs;
public LoginPage()
{
var cryptoService = Resolver.Resolve<ICryptoService>();
var authService = Resolver.Resolve<IAuthService>();
var deviceInfo = Resolver.Resolve<IDeviceInfo>();
var appIdService = Resolver.Resolve<IAppIdService>();
_cryptoService = Resolver.Resolve<ICryptoService>();
_authService = Resolver.Resolve<IAuthService>();
_deviceInfo = Resolver.Resolve<IDeviceInfo>();
_appIdService = Resolver.Resolve<IAppIdService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
var emailEntry = new Entry
Init();
}
public FormEntryCell PasswordCell { get; set; }
public FormEntryCell EmailCell { get; set; }
private void Init()
{
PasswordCell = new FormEntryCell(AppResources.MasterPassword, IsPassword: true);
EmailCell = new FormEntryCell(AppResources.EmailAddress, nextElement: PasswordCell.Entry, entryKeyboard: Keyboard.Email);
PasswordCell.Entry.ReturnType = Enums.ReturnType.Go;
PasswordCell.Entry.Completed += Entry_Completed;
var table = new ExtendedTableView
{
Keyboard = Keyboard.Email,
Placeholder = AppResources.EmailAddress
};
emailEntry.Behaviors.Add(new RequiredValidationBehavior());
emailEntry.Behaviors.Add(new EmailValidationBehavior());
var masterPasswordEntry = new Entry
{
IsPassword = true,
Placeholder = AppResources.MasterPassword
};
masterPasswordEntry.Behaviors.Add(new RequiredValidationBehavior());
var loginButton = new Button
{
Text = AppResources.LogIn,
Command = new Command(async () =>
Intent = TableIntent.Settings,
EnableScrolling = false,
HasUnevenRows = true,
EnableSelection = false,
Root = new TableRoot
{
if(string.IsNullOrWhiteSpace(emailEntry.Text))
new TableSection()
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok);
return;
EmailCell,
PasswordCell
}
if(string.IsNullOrWhiteSpace(masterPasswordEntry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok);
return;
}
var key = cryptoService.MakeKeyFromPassword(masterPasswordEntry.Text, emailEntry.Text);
var request = new TokenRequest
{
Email = emailEntry.Text,
MasterPasswordHash = cryptoService.HashPasswordBase64(key, masterPasswordEntry.Text),
Device = new DeviceRequest(appIdService, deviceInfo)
};
var response = await authService.TokenPostAsync(request);
if(!response.Succeeded)
{
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);
return;
}
cryptoService.Key = key;
authService.Token = response.Result.Token;
authService.UserId = response.Result.Profile.Id;
Application.Current.MainPage = new MainPage();
})
}
};
var stackLayout = new StackLayout
var loginToolbarItem = new ToolbarItem(AppResources.LogIn, null, async () =>
{
Padding = new Thickness(10, 50, 10, 0)
};
stackLayout.Children.Add(emailEntry);
stackLayout.Children.Add(masterPasswordEntry);
stackLayout.Children.Add(loginButton);
await LogIn();
}, ToolbarItemOrder.Default, 0);
if(Device.OS == TargetPlatform.iOS)
{
table.RowHeight = -1;
table.EstimatedRowHeight = 70;
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
}
Title = AppResources.LogIn;
Content = stackLayout;
BackgroundImage = "bg.png";
ToolbarItems.Add(loginToolbarItem);
Title = AppResources.Bitwarden;
Content = table;
}
protected override void OnAppearing()
{
base.OnAppearing();
EmailCell.Entry.Focus();
}
private void Entry_Completed(object sender, EventArgs e)
{
LogIn().Wait();
}
private async Task LogIn()
{
if(string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok);
return;
}
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok);
return;
}
var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, EmailCell.Entry.Text);
var request = new TokenRequest
{
Email = EmailCell.Entry.Text,
MasterPasswordHash = _cryptoService.HashPasswordBase64(key, PasswordCell.Entry.Text),
Device = new DeviceRequest(_appIdService, _deviceInfo)
};
var responseTask = _authService.TokenPostAsync(request);
_userDialogs.ShowLoading("Logging in...", MaskType.Black);
var response = await responseTask;
_userDialogs.HideLoading();
if(!response.Succeeded)
{
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);
return;
}
_cryptoService.Key = key;
_authService.Token = response.Result.Token;
_authService.UserId = response.Result.Profile.Id;
Application.Current.MainPage = new MainPage();
}
}
}

View file

@ -97,6 +97,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to bitwarden.
/// </summary>
internal static string Bitwarden {
get {
return ResourceManager.GetString("Bitwarden", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cancel.
/// </summary>

View file

@ -133,6 +133,10 @@
<value>Back</value>
<comment>Navigate back to the previous screen.</comment>
</data>
<data name="Bitwarden" xml:space="preserve">
<value>bitwarden</value>
<comment>App name. Shouldn't ever change.</comment>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
<comment>Cancel an operation.</comment>