1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-26 10:36:21 +02:00

scan totp key

This commit is contained in:
Kyle Spearrin 2019-05-22 21:10:04 -04:00
parent b5522c1b5e
commit bfa336b72d
5 changed files with 60 additions and 7 deletions

View File

@ -124,14 +124,34 @@
Grid.Column="3"
Grid.RowSpan="2" />
</Grid>
<StackLayout StyleClass="box-row">
<Grid StyleClass="box-row, box-row-input">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Text="{u:I18n AuthenticatorKey}"
StyleClass="box-label" />
StyleClass="box-label"
Grid.Row="0"
Grid.Column="0" />
<controls:MonoEntry
Text="{Binding Cipher.Login.Totp}"
StyleClass="box-value" />
</StackLayout>
StyleClass="box-value"
Grid.Row="1"
Grid.Column="0" />
<controls:FaButton
StyleClass="box-row-button, box-row-button-platform"
Text="&#xf030;"
Clicked="ScanTotp_Clicked"
Grid.Row="0"
Grid.Column="1"
Grid.RowSpan="2" />
</Grid>
</StackLayout>
<StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0">
<StackLayout StyleClass="box-row, box-row-input">

View File

@ -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));
}
}
}
}

View File

@ -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)

View File

@ -46,7 +46,7 @@
Grid.Row="0"
VerticalOptions="Center"
HorizontalOptions="Center"
BackgroundColor="White" />
TextColor="White" />
<BoxView
Grid.Column="0"
@ -70,7 +70,7 @@
Grid.Row="2"
VerticalOptions="Center"
HorizontalOptions="Center"
BackgroundColor="White" />
TextColor="White" />
</Grid>
</Grid>

View File

@ -14,13 +14,13 @@ namespace Bit.App.Pages
public ScanPage(Action<string> callback)
{
_callback = callback;
InitializeComponent();
_zxing.Options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
UseNativeScanning = true,
PossibleFormats = new List<ZXing.BarcodeFormat> { ZXing.BarcodeFormat.QR_CODE },
AutoRotate = false,
};
InitializeComponent();
}
protected override void OnAppearing()