From 786f3b4644d28b7f197cc1e7ad3a341a6138ff35 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 28 May 2019 10:12:51 -0400 Subject: [PATCH] 2fa for email --- src/App/Pages/Accounts/TwoFactorPage.xaml | 5 ++++ src/App/Pages/Accounts/TwoFactorPage.xaml.cs | 4 +++ .../Pages/Accounts/TwoFactorPageViewModel.cs | 28 +++++++++++-------- src/Core/Services/AuthService.cs | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/App/Pages/Accounts/TwoFactorPage.xaml b/src/App/Pages/Accounts/TwoFactorPage.xaml index fe1f7d471..004eeecba 100644 --- a/src/App/Pages/Accounts/TwoFactorPage.xaml +++ b/src/App/Pages/Accounts/TwoFactorPage.xaml @@ -36,6 +36,7 @@ StyleClass="box-label" /> @@ -109,6 +110,10 @@ Margin="10, 20, 10, 10" HorizontalTextAlignment="Center" /> + diff --git a/src/App/Pages/Accounts/TwoFactorPage.xaml.cs b/src/App/Pages/Accounts/TwoFactorPage.xaml.cs index 783ada8cc..23913b9eb 100644 --- a/src/App/Pages/Accounts/TwoFactorPage.xaml.cs +++ b/src/App/Pages/Accounts/TwoFactorPage.xaml.cs @@ -67,6 +67,10 @@ namespace Bit.App.Pages await LoadOnAppearedAsync(_scrollView, true, () => { _vm.Init(); + if(_vm.TotpMethod) + { + RequestFocus(_totpEntry); + } return Task.FromResult(0); }); } diff --git a/src/App/Pages/Accounts/TwoFactorPageViewModel.cs b/src/App/Pages/Accounts/TwoFactorPageViewModel.cs index ebbab4057..d187e26a8 100644 --- a/src/App/Pages/Accounts/TwoFactorPageViewModel.cs +++ b/src/App/Pages/Accounts/TwoFactorPageViewModel.cs @@ -26,7 +26,7 @@ namespace Bit.App.Pages private bool _u2fSupported = false; private TwoFactorProviderType? _selectedProviderType; - private string _twoFactorEmail; + private string _totpInstruction; private string _webVaultUrl = "https://vault.bitwarden.com"; public TwoFactorPageViewModel() @@ -44,10 +44,10 @@ namespace Bit.App.Pages PageTitle = AppResources.TwoStepLogin; } - public string TwoFactorEmail + public string TotpInstruction { - get => _twoFactorEmail; - set => SetProperty(ref _twoFactorEmail, value); + get => _totpInstruction; + set => SetProperty(ref _totpInstruction, value); } public bool Remember { get; set; } @@ -65,9 +65,6 @@ namespace Bit.App.Pages public bool TotpMethod => AuthenticatorMethod || EmailMethod; - public string TotpInstruction => AuthenticatorMethod ? AppResources.EnterVerificationCodeApp : - AppResources.EnterVerificationCodeEmail; - public string YubikeyInstruction => Device.RuntimePlatform == Device.iOS ? AppResources.YubiKeyInstructionIos : AppResources.YubiKeyInstruction; @@ -81,7 +78,6 @@ namespace Bit.App.Pages nameof(YubikeyMethod), nameof(AuthenticatorMethod), nameof(TotpMethod), - nameof(TotpInstruction) }); } @@ -141,12 +137,16 @@ namespace Bit.App.Pages }); break; case TwoFactorProviderType.Email: - TwoFactorEmail = providerData["Email"] as string; + TotpInstruction = string.Format(AppResources.EnterVerificationCodeEmail, + providerData["Email"] as string); if(_authService.TwoFactorProvidersData.Count > 1) { var emailTask = Task.Run(() => SendEmailAsync(false, false)); } break; + case TwoFactorProviderType.Authenticator: + TotpInstruction = AppResources.EnterVerificationCodeApp; + break; default: break; } @@ -212,9 +212,15 @@ namespace Bit.App.Pages { _platformUtilsService.LaunchUri("https://help.bitwarden.com/article/lost-two-step-device/"); } - else + else if(method != AppResources.Cancel) { - SelectedProviderType = supportedProviders.FirstOrDefault(p => p.Name == method)?.Type; + var selected = supportedProviders.FirstOrDefault(p => p.Name == method)?.Type; + if(selected == SelectedProviderType) + { + // Nothing changed + return; + } + SelectedProviderType = selected; Load(); } } diff --git a/src/Core/Services/AuthService.cs b/src/Core/Services/AuthService.cs index 4d5a24ffa..73ce0653c 100644 --- a/src/Core/Services/AuthService.cs +++ b/src/Core/Services/AuthService.cs @@ -98,7 +98,7 @@ namespace Bit.Core.Services public void Init() { - TwoFactorProviders[TwoFactorProviderType.Email].Name = _i18nService.T("EmailTitle"); + TwoFactorProviders[TwoFactorProviderType.Email].Name = _i18nService.T("Email"); TwoFactorProviders[TwoFactorProviderType.Email].Description = _i18nService.T("EmailDesc"); TwoFactorProviders[TwoFactorProviderType.Authenticator].Name = _i18nService.T("AuthenticatorAppTitle"); TwoFactorProviders[TwoFactorProviderType.Authenticator].Description =