mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-22 11:35:21 +01:00
Login page updates
This commit is contained in:
parent
a437731bfa
commit
3532037700
5780
src/Android/Resources/Resource.Designer.cs
generated
5780
src/Android/Resources/Resource.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -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 = {
|
||||
|
@ -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" />
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
{
|
||||
Keyboard = Keyboard.Email,
|
||||
Placeholder = AppResources.EmailAddress
|
||||
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
|
||||
{
|
||||
Intent = TableIntent.Settings,
|
||||
EnableScrolling = false,
|
||||
HasUnevenRows = true,
|
||||
EnableSelection = false,
|
||||
Root = new TableRoot
|
||||
{
|
||||
new TableSection()
|
||||
{
|
||||
EmailCell,
|
||||
PasswordCell
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
emailEntry.Behaviors.Add(new RequiredValidationBehavior());
|
||||
emailEntry.Behaviors.Add(new EmailValidationBehavior());
|
||||
|
||||
var masterPasswordEntry = new Entry
|
||||
var loginToolbarItem = new ToolbarItem(AppResources.LogIn, null, async () =>
|
||||
{
|
||||
IsPassword = true,
|
||||
Placeholder = AppResources.MasterPassword
|
||||
};
|
||||
await LogIn();
|
||||
}, ToolbarItemOrder.Default, 0);
|
||||
|
||||
masterPasswordEntry.Behaviors.Add(new RequiredValidationBehavior());
|
||||
if(Device.OS == TargetPlatform.iOS)
|
||||
{
|
||||
table.RowHeight = -1;
|
||||
table.EstimatedRowHeight = 70;
|
||||
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
||||
}
|
||||
|
||||
var loginButton = new Button
|
||||
ToolbarItems.Add(loginToolbarItem);
|
||||
Title = AppResources.Bitwarden;
|
||||
Content = table;
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
Text = AppResources.LogIn,
|
||||
Command = new Command(async () =>
|
||||
base.OnAppearing();
|
||||
EmailCell.Entry.Focus();
|
||||
}
|
||||
|
||||
private void Entry_Completed(object sender, EventArgs e)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(emailEntry.Text))
|
||||
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(masterPasswordEntry.Text))
|
||||
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
|
||||
{
|
||||
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
var key = cryptoService.MakeKeyFromPassword(masterPasswordEntry.Text, emailEntry.Text);
|
||||
var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, EmailCell.Entry.Text);
|
||||
|
||||
var request = new TokenRequest
|
||||
{
|
||||
Email = emailEntry.Text,
|
||||
MasterPasswordHash = cryptoService.HashPasswordBase64(key, masterPasswordEntry.Text),
|
||||
Device = new DeviceRequest(appIdService, deviceInfo)
|
||||
Email = EmailCell.Entry.Text,
|
||||
MasterPasswordHash = _cryptoService.HashPasswordBase64(key, PasswordCell.Entry.Text),
|
||||
Device = new DeviceRequest(_appIdService, _deviceInfo)
|
||||
};
|
||||
|
||||
var response = await authService.TokenPostAsync(request);
|
||||
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;
|
||||
_cryptoService.Key = key;
|
||||
_authService.Token = response.Result.Token;
|
||||
_authService.UserId = response.Result.Profile.Id;
|
||||
|
||||
Application.Current.MainPage = new MainPage();
|
||||
})
|
||||
};
|
||||
|
||||
var stackLayout = new StackLayout
|
||||
{
|
||||
Padding = new Thickness(10, 50, 10, 0)
|
||||
};
|
||||
stackLayout.Children.Add(emailEntry);
|
||||
stackLayout.Children.Add(masterPasswordEntry);
|
||||
stackLayout.Children.Add(loginButton);
|
||||
|
||||
if(Device.OS == TargetPlatform.iOS)
|
||||
{
|
||||
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
||||
}
|
||||
|
||||
Title = AppResources.LogIn;
|
||||
Content = stackLayout;
|
||||
BackgroundImage = "bg.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
src/App/Resources/AppResources.Designer.cs
generated
9
src/App/Resources/AppResources.Designer.cs
generated
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user