2020-04-13 18:32:23 +02:00
|
|
|
|
using Bit.App.Models;
|
2020-11-12 17:23:34 +01:00
|
|
|
|
using Bit.App.Resources;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
using Bit.Core.Abstractions;
|
2019-06-26 16:05:31 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using System;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2020-09-03 18:30:40 +02:00
|
|
|
|
using Bit.App.Utilities;
|
2019-04-19 15:42:55 +02:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2019-05-01 21:29:57 +02:00
|
|
|
|
public partial class LoginPage : BaseContentPage
|
2019-04-19 15:42:55 +02:00
|
|
|
|
{
|
2019-06-26 16:05:31 +02:00
|
|
|
|
private readonly IMessagingService _messagingService;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
private readonly IStorageService _storageService;
|
2019-06-26 16:05:31 +02:00
|
|
|
|
private readonly LoginPageViewModel _vm;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
private readonly AppOptions _appOptions;
|
2019-04-19 15:42:55 +02:00
|
|
|
|
|
2021-08-30 18:44:12 +02:00
|
|
|
|
private bool _inputFocused;
|
|
|
|
|
|
2020-04-13 18:32:23 +02:00
|
|
|
|
public LoginPage(string email = null, AppOptions appOptions = null)
|
2019-04-19 15:42:55 +02:00
|
|
|
|
{
|
2020-04-13 18:32:23 +02:00
|
|
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
2019-06-26 16:05:31 +02:00
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
|
|
|
|
_messagingService.Send("showStatusBar", true);
|
2020-04-13 18:32:23 +02:00
|
|
|
|
_appOptions = appOptions;
|
2019-04-19 15:42:55 +02:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
_vm = BindingContext as LoginPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
_vm.StartTwoFactorAction = () => Device.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
|
2020-09-03 18:30:40 +02:00
|
|
|
|
_vm.LogInSuccessAction = () => Device.BeginInvokeOnMainThread(async () => await LogInSuccessAsync());
|
2021-09-24 20:14:26 +02:00
|
|
|
|
_vm.UpdateTempPasswordAction =
|
|
|
|
|
() => Device.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync());
|
2020-05-29 18:26:36 +02:00
|
|
|
|
_vm.CloseAction = async () =>
|
|
|
|
|
{
|
|
|
|
|
_messagingService.Send("showStatusBar", false);
|
|
|
|
|
await Navigation.PopModalAsync();
|
|
|
|
|
};
|
2019-06-05 05:07:35 +02:00
|
|
|
|
_vm.Email = email;
|
2019-05-01 21:29:57 +02:00
|
|
|
|
MasterPasswordEntry = _masterPassword;
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
2019-06-12 03:31:51 +02:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.RemoveAt(0);
|
|
|
|
|
}
|
2019-05-31 18:02:40 +02:00
|
|
|
|
|
|
|
|
|
_email.ReturnType = ReturnType.Next;
|
|
|
|
|
_email.ReturnCommand = new Command(() => _masterPassword.Focus());
|
2020-11-12 17:23:34 +01:00
|
|
|
|
|
|
|
|
|
if (Device.RuntimePlatform == Device.iOS)
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(_moreItem);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(_getPasswordHint);
|
|
|
|
|
}
|
2019-05-01 21:29:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Entry MasterPasswordEntry { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override async void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
|
|
|
|
await _vm.InitAsync();
|
2021-08-30 18:44:12 +02:00
|
|
|
|
if (!_inputFocused)
|
2019-05-01 21:29:57 +02:00
|
|
|
|
{
|
2021-08-30 18:44:12 +02:00
|
|
|
|
RequestFocus(string.IsNullOrWhiteSpace(_vm.Email) ? _email : _masterPassword);
|
|
|
|
|
_inputFocused = true;
|
2019-05-01 21:29:57 +02:00
|
|
|
|
}
|
2019-04-19 15:42:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void LogIn_Clicked(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (DoOnce())
|
2019-05-07 05:30:54 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.LogInAsync();
|
|
|
|
|
}
|
2019-04-19 15:42:55 +02:00
|
|
|
|
}
|
2019-05-01 21:53:56 +02:00
|
|
|
|
|
|
|
|
|
private void Hint_Clicked(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (DoOnce())
|
2019-05-07 05:30:54 +02:00
|
|
|
|
{
|
|
|
|
|
Navigation.PushModalAsync(new NavigationPage(new HintPage()));
|
|
|
|
|
}
|
2019-05-01 21:53:56 +02:00
|
|
|
|
}
|
2019-06-12 03:31:51 +02:00
|
|
|
|
|
2020-09-03 18:30:40 +02:00
|
|
|
|
private void Close_Clicked(object sender, EventArgs e)
|
2019-06-12 03:31:51 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (DoOnce())
|
2019-06-12 03:31:51 +02:00
|
|
|
|
{
|
2020-05-29 18:26:36 +02:00
|
|
|
|
_vm.CloseAction();
|
2019-06-12 03:31:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-13 18:32:23 +02:00
|
|
|
|
|
2020-11-12 17:23:34 +01:00
|
|
|
|
private async void More_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!DoOnce())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var selection = await DisplayActionSheet(AppResources.Options,
|
|
|
|
|
AppResources.Cancel, null, AppResources.GetPasswordHint);
|
|
|
|
|
|
|
|
|
|
if (selection == AppResources.GetPasswordHint)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new HintPage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 18:32:23 +02:00
|
|
|
|
private async Task StartTwoFactorAsync()
|
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
var page = new TwoFactorPage(false, _appOptions);
|
2020-04-13 18:32:23 +02:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
|
|
|
}
|
2020-05-29 18:26:36 +02:00
|
|
|
|
|
2020-09-03 18:30:40 +02:00
|
|
|
|
private async Task LogInSuccessAsync()
|
2020-04-13 18:32:23 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
if (AppHelpers.SetAlternateMainPage(_appOptions))
|
2020-04-13 18:32:23 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
return;
|
2020-04-13 18:32:23 +02:00
|
|
|
|
}
|
2020-09-03 18:30:40 +02:00
|
|
|
|
var previousPage = await AppHelpers.ClearPreviousPage();
|
2020-04-13 18:32:23 +02:00
|
|
|
|
Application.Current.MainPage = new TabsPage(_appOptions, previousPage);
|
|
|
|
|
}
|
2021-09-24 20:14:26 +02:00
|
|
|
|
|
|
|
|
|
private async Task UpdateTempPasswordAsync()
|
|
|
|
|
{
|
|
|
|
|
var page = new UpdateTempPasswordPage();
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
|
|
|
}
|
2019-04-19 15:42:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|