mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Acr.UserDialogs;
|
|
using Bit.App.Abstractions;
|
|
using Bit.App.Controls;
|
|
using Bit.App.Resources;
|
|
using Xamarin.Forms;
|
|
using XLabs.Ioc;
|
|
using Plugin.Fingerprint.Abstractions;
|
|
using Plugin.Settings.Abstractions;
|
|
|
|
namespace Bit.App.Pages
|
|
{
|
|
public class LockFingerprintPage : ExtendedContentPage
|
|
{
|
|
private readonly IFingerprint _fingerprint;
|
|
private readonly IAuthService _authService;
|
|
private readonly IUserDialogs _userDialogs;
|
|
private readonly ISettings _settings;
|
|
private readonly bool _checkFingerprintImmediately;
|
|
|
|
public LockFingerprintPage(bool checkFingerprintImmediately)
|
|
{
|
|
_checkFingerprintImmediately = checkFingerprintImmediately;
|
|
_fingerprint = Resolver.Resolve<IFingerprint>();
|
|
_authService = Resolver.Resolve<IAuthService>();
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
_settings = Resolver.Resolve<ISettings>();
|
|
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
var fingerprintButton = new Button
|
|
{
|
|
Text = "Use Fingerprint to Unlock",
|
|
Command = new Command(async () => await CheckFingerprintAsync()),
|
|
VerticalOptions = LayoutOptions.EndAndExpand,
|
|
Style = (Style)Application.Current.Resources["btn-default"]
|
|
};
|
|
|
|
var logoutButton = new Button
|
|
{
|
|
Text = AppResources.LogOut,
|
|
Command = new Command(async () => await LogoutAsync()),
|
|
VerticalOptions = LayoutOptions.End,
|
|
Style = (Style)Application.Current.Resources["btn-default"]
|
|
};
|
|
|
|
var stackLayout = new StackLayout { Padding = new Thickness(30, 40), Spacing = 10 };
|
|
stackLayout.Children.Add(fingerprintButton);
|
|
stackLayout.Children.Add(logoutButton);
|
|
|
|
Title = "Verify Fingerprint";
|
|
Content = stackLayout;
|
|
}
|
|
|
|
protected override bool OnBackButtonPressed()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
protected override void OnAppearing()
|
|
{
|
|
base.OnAppearing();
|
|
|
|
if(_checkFingerprintImmediately)
|
|
{
|
|
CheckFingerprintAsync();
|
|
}
|
|
}
|
|
|
|
public async Task LogoutAsync()
|
|
{
|
|
if(!await _userDialogs.ConfirmAsync("Are you sure you want to log out?", null, AppResources.Yes, AppResources.Cancel))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_authService.LogOut();
|
|
await Navigation.PopModalAsync();
|
|
Application.Current.MainPage = new HomePage();
|
|
}
|
|
|
|
public async Task CheckFingerprintAsync()
|
|
{
|
|
var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify.");
|
|
if(result.Authenticated)
|
|
{
|
|
await Navigation.PopModalAsync();
|
|
}
|
|
}
|
|
}
|
|
}
|