1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-26 12:16:07 +01:00

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)) Resources.Add(new Style(typeof(Button))
{ {
Setters = { Setters = {

View File

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

View File

@ -6,6 +6,7 @@ using Bit.App.Resources;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
using Bit.App.Controls;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
@ -36,15 +37,18 @@ namespace Bit.App.Pages
var message = new Label var message = new Label
{ {
Text = "Welcome!", Text = "Log in or create a new account to access your secure vault.",
VerticalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.Center HorizontalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center,
LineBreakMode = LineBreakMode.WordWrap,
FontSize = 20
}; };
var createAccountButton = new Button var createAccountButton = new Button
{ {
Text = "Create Account", Text = "Create Account",
//Command = new Command(async () => await LogoutAsync()), //Command = new Command(async () => await RegisterAsync()),
VerticalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End,
HorizontalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill,
Style = (Style)Application.Current.Resources["btn-primary"], Style = (Style)Application.Current.Resources["btn-primary"],
@ -75,7 +79,7 @@ namespace Bit.App.Pages
public async Task LoginAsync() 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;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Behaviors;
using Bit.App.Controls; using Bit.App.Controls;
using Bit.App.Models.Api; using Bit.App.Models.Api;
using Bit.App.Resources; using Bit.App.Resources;
using Plugin.DeviceInfo.Abstractions; using Plugin.DeviceInfo.Abstractions;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
using Acr.UserDialogs;
using System.Threading.Tasks;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public class LoginPage : ContentPage public class LoginPage : ContentPage
{ {
private ICryptoService _cryptoService;
private IAuthService _authService;
private IDeviceInfo _deviceInfo;
private IAppIdService _appIdService;
private IUserDialogs _userDialogs;
public LoginPage() public LoginPage()
{ {
var cryptoService = Resolver.Resolve<ICryptoService>(); _cryptoService = Resolver.Resolve<ICryptoService>();
var authService = Resolver.Resolve<IAuthService>(); _authService = Resolver.Resolve<IAuthService>();
var deviceInfo = Resolver.Resolve<IDeviceInfo>(); _deviceInfo = Resolver.Resolve<IDeviceInfo>();
var appIdService = Resolver.Resolve<IAppIdService>(); _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, Intent = TableIntent.Settings,
Placeholder = AppResources.EmailAddress EnableScrolling = false,
}; HasUnevenRows = true,
EnableSelection = false,
emailEntry.Behaviors.Add(new RequiredValidationBehavior()); Root = new TableRoot
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 () =>
{ {
if(string.IsNullOrWhiteSpace(emailEntry.Text)) new TableSection()
{ {
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok); EmailCell,
return; 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) await LogIn();
}; }, ToolbarItemOrder.Default, 0);
stackLayout.Children.Add(emailEntry);
stackLayout.Children.Add(masterPasswordEntry);
stackLayout.Children.Add(loginButton);
if(Device.OS == TargetPlatform.iOS) if(Device.OS == TargetPlatform.iOS)
{ {
table.RowHeight = -1;
table.EstimatedRowHeight = 70;
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel")); ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
} }
Title = AppResources.LogIn; ToolbarItems.Add(loginToolbarItem);
Content = stackLayout; Title = AppResources.Bitwarden;
BackgroundImage = "bg.png"; 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> /// <summary>
/// Looks up a localized string similar to Cancel. /// Looks up a localized string similar to Cancel.
/// </summary> /// </summary>

View File

@ -133,6 +133,10 @@
<value>Back</value> <value>Back</value>
<comment>Navigate back to the previous screen.</comment> <comment>Navigate back to the previous screen.</comment>
</data> </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"> <data name="Cancel" xml:space="preserve">
<value>Cancel</value> <value>Cancel</value>
<comment>Cancel an operation.</comment> <comment>Cancel an operation.</comment>