mirror of
https://github.com/bitwarden/mobile.git
synced 2025-01-28 22:11:33 +01:00
init login page
This commit is contained in:
parent
3b97fa0379
commit
9678eab43f
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage
|
<pages:BaseContentPage
|
||||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="Bit.App.Pages.LoginPage"
|
x:Class="Bit.App.Pages.LoginPage"
|
||||||
@ -31,6 +31,7 @@
|
|||||||
Text="{u:I18n EmailAddress}"
|
Text="{u:I18n EmailAddress}"
|
||||||
StyleClass="box-label" />
|
StyleClass="box-label" />
|
||||||
<Entry
|
<Entry
|
||||||
|
x:Name="_email"
|
||||||
Text="{Binding Email}"
|
Text="{Binding Email}"
|
||||||
StyleClass="box-value" />
|
StyleClass="box-value" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
@ -49,6 +50,7 @@
|
|||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="0" />
|
Grid.Column="0" />
|
||||||
<controls:MonoEntry
|
<controls:MonoEntry
|
||||||
|
x:Name="_masterPassword"
|
||||||
Text="{Binding MasterPassword}"
|
Text="{Binding MasterPassword}"
|
||||||
StyleClass="box-value"
|
StyleClass="box-value"
|
||||||
IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
|
IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
|
||||||
@ -69,4 +71,4 @@
|
|||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
</ContentPage>
|
</pages:BaseContentPage>
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Xaml;
|
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
public partial class LoginPage : ContentPage
|
public partial class LoginPage : BaseContentPage
|
||||||
{
|
{
|
||||||
private LoginPageViewModel _vm;
|
private LoginPageViewModel _vm;
|
||||||
|
|
||||||
@ -17,6 +12,23 @@ namespace Bit.App.Pages
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_vm = BindingContext as LoginPageViewModel;
|
_vm = BindingContext as LoginPageViewModel;
|
||||||
_vm.Page = this;
|
_vm.Page = this;
|
||||||
|
MasterPasswordEntry = _masterPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entry MasterPasswordEntry { get; set; }
|
||||||
|
|
||||||
|
protected override async void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
await _vm.InitAsync();
|
||||||
|
if(string.IsNullOrWhiteSpace(_vm.Email))
|
||||||
|
{
|
||||||
|
RequestFocus(_email);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RequestFocus(_masterPassword);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void LogIn_Clicked(object sender, EventArgs e)
|
private async void LogIn_Clicked(object sender, EventArgs e)
|
||||||
|
@ -10,9 +10,13 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
public class LoginPageViewModel : BaseViewModel
|
public class LoginPageViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
|
private const string Keys_RememberedEmail = "rememberedEmail";
|
||||||
|
private const string Keys_RememberEmail = "rememberEmail";
|
||||||
|
|
||||||
private readonly IDeviceActionService _deviceActionService;
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
private readonly ISyncService _syncService;
|
private readonly ISyncService _syncService;
|
||||||
|
private readonly IStorageService _storageService;
|
||||||
|
|
||||||
private bool _showPassword;
|
private bool _showPassword;
|
||||||
|
|
||||||
@ -21,6 +25,7 @@ namespace Bit.App.Pages
|
|||||||
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
_authService = ServiceContainer.Resolve<IAuthService>("authService");
|
_authService = ServiceContainer.Resolve<IAuthService>("authService");
|
||||||
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
||||||
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
||||||
|
|
||||||
PageTitle = AppResources.Bitwarden;
|
PageTitle = AppResources.Bitwarden;
|
||||||
TogglePasswordCommand = new Command(TogglePassword);
|
TogglePasswordCommand = new Command(TogglePassword);
|
||||||
@ -40,6 +45,17 @@ namespace Bit.App.Pages
|
|||||||
public string ShowPasswordIcon => ShowPassword ? "" : "";
|
public string ShowPasswordIcon => ShowPassword ? "" : "";
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
public string MasterPassword { get; set; }
|
public string MasterPassword { get; set; }
|
||||||
|
public bool RememberEmail { get; set; }
|
||||||
|
|
||||||
|
public async Task InitAsync()
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(Email))
|
||||||
|
{
|
||||||
|
Email = await _storageService.GetAsync<string>(Keys_RememberedEmail);
|
||||||
|
}
|
||||||
|
var rememberEmail = await _storageService.GetAsync<bool?>(Keys_RememberEmail);
|
||||||
|
RememberEmail = rememberEmail.GetValueOrDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task LogInAsync()
|
public async Task LogInAsync()
|
||||||
{
|
{
|
||||||
@ -68,7 +84,14 @@ namespace Bit.App.Pages
|
|||||||
await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn);
|
await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn);
|
||||||
var response = await _authService.LogInAsync(Email, MasterPassword);
|
var response = await _authService.LogInAsync(Email, MasterPassword);
|
||||||
await _deviceActionService.HideLoadingAsync();
|
await _deviceActionService.HideLoadingAsync();
|
||||||
// TODO: remember email?
|
if(RememberEmail)
|
||||||
|
{
|
||||||
|
await _storageService.SaveAsync(Keys_RememberedEmail, Email);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _storageService.RemoveAsync(Keys_RememberedEmail);
|
||||||
|
}
|
||||||
if(response.TwoFactor)
|
if(response.TwoFactor)
|
||||||
{
|
{
|
||||||
// TODO: 2fa page
|
// TODO: 2fa page
|
||||||
@ -89,6 +112,7 @@ namespace Bit.App.Pages
|
|||||||
public void TogglePassword()
|
public void TogglePassword()
|
||||||
{
|
{
|
||||||
ShowPassword = !ShowPassword;
|
ShowPassword = !ShowPassword;
|
||||||
|
(Page as LoginPage).MasterPasswordEntry.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
public class BaseContentPage : ContentPage
|
public class BaseContentPage : ContentPage
|
||||||
{
|
{
|
||||||
|
protected int AndroidShowModalAnimationDelay = 400;
|
||||||
|
|
||||||
protected void SetActivityIndicator()
|
protected void SetActivityIndicator()
|
||||||
{
|
{
|
||||||
Content = new ActivityIndicator
|
Content = new ActivityIndicator
|
||||||
@ -33,9 +35,23 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(400);
|
await Task.Delay(AndroidShowModalAnimationDelay);
|
||||||
Device.BeginInvokeOnMainThread(async () => await DoWorkAsync());
|
Device.BeginInvokeOnMainThread(async () => await DoWorkAsync());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void RequestFocus(Entry entry)
|
||||||
|
{
|
||||||
|
if(Device.RuntimePlatform == Device.iOS)
|
||||||
|
{
|
||||||
|
entry.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(AndroidShowModalAnimationDelay);
|
||||||
|
Device.BeginInvokeOnMainThread(() => entry.Focus());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user