From bfa336b72dcd879f5b9e730f62221f8f64428916 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 22 May 2019 21:10:04 -0400 Subject: [PATCH] scan totp key --- src/App/Pages/Vault/AddEditPage.xaml | 28 ++++++++++++++++++--- src/App/Pages/Vault/AddEditPage.xaml.cs | 16 ++++++++++++ src/App/Pages/Vault/AddEditPageViewModel.cs | 17 +++++++++++++ src/App/Pages/Vault/ScanPage.xaml | 4 +-- src/App/Pages/Vault/ScanPage.xaml.cs | 2 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/App/Pages/Vault/AddEditPage.xaml b/src/App/Pages/Vault/AddEditPage.xaml index 16d2cfd99..8df6d74fa 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml +++ b/src/App/Pages/Vault/AddEditPage.xaml @@ -124,14 +124,34 @@ Grid.Column="3" Grid.RowSpan="2" /> - + + + + + + + + + + + StyleClass="box-value" + Grid.Row="1" + Grid.Column="0" /> + + diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index 569c94a49..5d23b056f 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -157,5 +157,21 @@ namespace Bit.App.Pages await Navigation.PushModalAsync(new NavigationPage(page)); } } + + private async void ScanTotp_Clicked(object sender, System.EventArgs e) + { + if(DoOnce()) + { + var page = new ScanPage(key => + { + Device.BeginInvokeOnMainThread(async () => + { + await Navigation.PopModalAsync(); + await _vm.UpdateTotpKeyAsync(key); + }); + }); + await Navigation.PushModalAsync(new NavigationPage(page)); + } + } } } diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index 49b2a518f..c4644f11e 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -576,6 +576,23 @@ namespace Bit.App.Pages ShowCardCode = !ShowCardCode; } + public async Task UpdateTotpKeyAsync(string key) + { + if(Cipher?.Login != null) + { + if(!string.IsNullOrWhiteSpace(key)) + { + Cipher.Login.Totp = key; + TriggerCipherChanged(); + _platformUtilsService.ShowToast("info", null, AppResources.AuthenticatorKeyAdded); + } + else + { + await _platformUtilsService.ShowDialogAsync(AppResources.AuthenticatorKeyReadError); + } + } + } + private void TypeChanged() { if(Cipher != null && TypeSelectedIndex > -1) diff --git a/src/App/Pages/Vault/ScanPage.xaml b/src/App/Pages/Vault/ScanPage.xaml index e3f6c7ef0..b6b6fff8a 100644 --- a/src/App/Pages/Vault/ScanPage.xaml +++ b/src/App/Pages/Vault/ScanPage.xaml @@ -46,7 +46,7 @@ Grid.Row="0" VerticalOptions="Center" HorizontalOptions="Center" - BackgroundColor="White" /> + TextColor="White" /> + TextColor="White" /> diff --git a/src/App/Pages/Vault/ScanPage.xaml.cs b/src/App/Pages/Vault/ScanPage.xaml.cs index 4937dd88d..8d61854bd 100644 --- a/src/App/Pages/Vault/ScanPage.xaml.cs +++ b/src/App/Pages/Vault/ScanPage.xaml.cs @@ -14,13 +14,13 @@ namespace Bit.App.Pages public ScanPage(Action callback) { _callback = callback; + InitializeComponent(); _zxing.Options = new ZXing.Mobile.MobileBarcodeScanningOptions { UseNativeScanning = true, PossibleFormats = new List { ZXing.BarcodeFormat.QR_CODE }, AutoRotate = false, }; - InitializeComponent(); } protected override void OnAppearing()