1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-11 05:43:30 +00: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.Column="3"
Grid.RowSpan="2" /> Grid.RowSpan="2" />
</Grid> </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 <Label
Text="{u:I18n AuthenticatorKey}" Text="{u:I18n AuthenticatorKey}"
StyleClass="box-label" /> StyleClass="box-label"
Grid.Row="0"
Grid.Column="0" />
<controls:MonoEntry <controls:MonoEntry
Text="{Binding Cipher.Login.Totp}" Text="{Binding Cipher.Login.Totp}"
StyleClass="box-value" /> StyleClass="box-value"
</StackLayout> 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>
<StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0"> <StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0">
<StackLayout StyleClass="box-row, box-row-input"> <StackLayout StyleClass="box-row, box-row-input">

View File

@@ -157,5 +157,21 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); 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; 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() private void TypeChanged()
{ {
if(Cipher != null && TypeSelectedIndex > -1) if(Cipher != null && TypeSelectedIndex > -1)

View File

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

View File

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