1
0
mirror of https://github.com/bitwarden/mobile synced 2026-02-26 01:13:28 +00:00

refactor message center use to services

This commit is contained in:
Kyle Spearrin
2017-11-21 23:08:45 -05:00
parent b48e8eeb0e
commit 3b44ede67e
24 changed files with 439 additions and 379 deletions

View File

@@ -12,9 +12,8 @@ namespace Bit.App.Abstractions
bool UserIdChanged { get; }
string Email { get; set; }
string PIN { get; set; }
bool BelongsToOrganization(string orgId);
void LogOut();
void LogOut(string logoutMessage = null);
Task<FullLoginResult> TokenPostAsync(string email, string masterPassword);
Task<LoginResult> TokenPostTwoFactorAsync(TwoFactorProviderType type, string token, bool remember, string email,
string masterPasswordHash, SymmetricCryptoKey key);

View File

@@ -10,5 +10,12 @@ namespace Bit.App.Abstractions
bool CanOpenFile(string fileName);
Task SelectFileAsync();
void ClearCache();
void Autofill(Models.Page.VaultListPageModel.Cipher cipher);
void CloseAutofill();
void Background();
void RateApp();
void DismissKeyboard();
void OpenAccessibilitySettings();
void LaunchApp(string appName);
}
}

View File

@@ -8,5 +8,7 @@ namespace Bit.App.Abstractions
{
void UpdateLastActivity(DateTime? activityDate = null);
Task<LockType> GetLockTypeAsync(bool forceLock);
Task CheckLockAsync(bool forceLock);
bool TopPageIsLock();
}
}

View File

@@ -86,27 +86,20 @@ namespace Bit.App
MainPage = new ExtendedNavigationPage(new HomePage());
}
MessagingCenter.Subscribe<Application, bool>(Current, "Resumed", async (sender, args) =>
if(Device.RuntimePlatform == Device.iOS)
{
Device.BeginInvokeOnMainThread(async () => await CheckLockAsync(args));
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
});
MessagingCenter.Subscribe<Application, bool>(Current, "Lock", (sender, args) =>
{
Device.BeginInvokeOnMainThread(async () => await CheckLockAsync(args));
});
MessagingCenter.Subscribe<Application, string>(Current, "Logout", (sender, args) =>
{
Logout(args);
});
MessagingCenter.Subscribe<Application, bool>(Current, "Resumed", async (sender, args) =>
{
Device.BeginInvokeOnMainThread(async () => await _lockService.CheckLockAsync(args));
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
});
}
}
protected async override void OnStart()
{
// Handle when your app starts
await CheckLockAsync(false);
await _lockService.CheckLockAsync(false);
if(string.IsNullOrWhiteSpace(_options.Uri))
{
@@ -132,7 +125,7 @@ namespace Bit.App
SetMainPageFromAutofill();
if(Device.RuntimePlatform == Device.Android && !TopPageIsLock())
if(Device.RuntimePlatform == Device.Android && !_lockService.TopPageIsLock())
{
_lockService.UpdateLastActivity();
}
@@ -151,7 +144,7 @@ namespace Bit.App
if(Device.RuntimePlatform == Device.Android)
{
await CheckLockAsync(false);
await _lockService.CheckLockAsync(false);
}
var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;
@@ -227,73 +220,6 @@ namespace Bit.App
}
}
private void Logout(string logoutMessage)
{
_authService.LogOut();
var deviceApiRepository = Resolver.Resolve<IDeviceApiRepository>();
var appIdService = Resolver.Resolve<IAppIdService>();
Task.Run(async () => await deviceApiRepository.PutClearTokenAsync(appIdService.AppId));
_googleAnalyticsService.TrackAppEvent("LoggedOut");
Device.BeginInvokeOnMainThread(() => Current.MainPage = new ExtendedNavigationPage(new HomePage()));
if(!string.IsNullOrWhiteSpace(logoutMessage))
{
_userDialogs.Toast(logoutMessage);
}
}
private async Task CheckLockAsync(bool forceLock)
{
if(TopPageIsLock())
{
// already locked
return;
}
var lockType = await _lockService.GetLockTypeAsync(forceLock);
if(lockType == Enums.LockType.None)
{
return;
}
_appSettingsService.Locked = true;
switch(lockType)
{
case Enums.LockType.Fingerprint:
await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockFingerprintPage(!forceLock)), false);
break;
case Enums.LockType.PIN:
await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockPinPage()), false);
break;
case Enums.LockType.Password:
await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockPasswordPage()), false);
break;
default:
break;
}
}
private bool TopPageIsLock()
{
var currentPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as ExtendedNavigationPage;
if((currentPage?.CurrentPage as LockFingerprintPage) != null)
{
return true;
}
if((currentPage?.CurrentPage as LockPinPage) != null)
{
return true;
}
if((currentPage?.CurrentPage as LockPasswordPage) != null)
{
return true;
}
return false;
}
private void SetStyles()
{
var gray = Color.FromHex("333333");

View File

@@ -1,6 +1,4 @@
using Bit.App.Abstractions;
using Plugin.Settings.Abstractions;
using System;
using Xamarin.Forms;
using XLabs.Ioc;
@@ -11,6 +9,7 @@ namespace Bit.App.Controls
private ISyncService _syncService;
private IGoogleAnalyticsService _googleAnalyticsService;
private ILockService _lockService;
private IDeviceActionService _deviceActionService;
private bool _syncIndicator;
private bool _updateActivity;
@@ -21,25 +20,21 @@ namespace Bit.App.Controls
_syncService = Resolver.Resolve<ISyncService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_lockService = Resolver.Resolve<ILockService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
BackgroundColor = Color.FromHex("efeff4");
if(_syncIndicator)
{
MessagingCenter.Subscribe<Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
{
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
});
MessagingCenter.Subscribe<Application>(Application.Current, "SyncStarted", (sender) =>
{
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
});
}
}
protected override void OnAppearing()
{
if(_syncIndicator)
{
MessagingCenter.Subscribe<ISyncService, bool>(_syncService, "SyncCompleted",
(sender, success) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress));
MessagingCenter.Subscribe<ISyncService>(_syncService, "SyncStarted",
(sender) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress));
}
if(_syncIndicator)
{
IsBusy = _syncService.SyncInProgress;
@@ -51,6 +46,12 @@ namespace Bit.App.Controls
protected override void OnDisappearing()
{
if(_syncIndicator)
{
MessagingCenter.Unsubscribe<ISyncService, bool>(_syncService, "SyncCompleted");
MessagingCenter.Unsubscribe<ISyncService>(_syncService, "SyncStarted");
}
if(_syncIndicator)
{
IsBusy = false;
@@ -62,7 +63,7 @@ namespace Bit.App.Controls
}
base.OnDisappearing();
MessagingCenter.Send(Application.Current, "DismissKeyboard");
_deviceActionService.DismissKeyboard();
}
}
}

View File

@@ -4,27 +4,28 @@ using Bit.App.Controls;
using Bit.App.Resources;
using Xamarin.Forms;
using XLabs.Ioc;
using Bit.App.Abstractions;
namespace Bit.App.Pages
{
public class BaseLockPage : ExtendedContentPage
{
private readonly IDeviceActionService _deviceActionService;
public BaseLockPage()
: base(false, false)
{
UserDialogs = Resolver.Resolve<IUserDialogs>();
AuthService = Resolver.Resolve<IAuthService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
}
protected IUserDialogs UserDialogs { get; set; }
protected IAuthService AuthService { get; set; }
protected override bool OnBackButtonPressed()
{
if(Device.RuntimePlatform == Device.Android)
{
MessagingCenter.Send(Application.Current, "BackgroundApp");
}
_deviceActionService.Background();
return true;
}
@@ -34,8 +35,7 @@ namespace Bit.App.Pages
{
return;
}
MessagingCenter.Send(Application.Current, "Logout", (string)null);
AuthService.LogOut();
}
}
}

View File

@@ -100,7 +100,7 @@ namespace Bit.App.Pages
}
else if(result.Status == FingerprintAuthenticationResultStatus.FallbackRequested)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
AuthService.LogOut();
}
}
}

View File

@@ -22,6 +22,7 @@ namespace Bit.App.Pages
private IUserDialogs _userDialogs;
private ISyncService _syncService;
private IDeviceInfoService _deviceInfoService;
private IDeviceActionService _deviceActionService;
private IGoogleAnalyticsService _googleAnalyticsService;
private ITwoFactorApiRepository _twoFactorApiRepository;
private IPushNotificationService _pushNotification;
@@ -45,6 +46,7 @@ namespace Bit.App.Pages
_providers = result.TwoFactorProviders;
_providerType = type ?? GetDefaultProvider();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_authService = Resolver.Resolve<IAuthService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_syncService = Resolver.Resolve<ISyncService>();
@@ -266,7 +268,7 @@ namespace Bit.App.Pages
InitEvents();
if(TokenCell == null && Device.RuntimePlatform == Device.Android)
{
MessagingCenter.Send(Application.Current, "DismissKeyboard");
_deviceActionService.DismissKeyboard();
}
}

View File

@@ -19,7 +19,8 @@ namespace Bit.App.Pages
private readonly IFingerprint _fingerprint;
private readonly IPushNotificationService _pushNotification;
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IDeviceInfoService _deviceInfoService;
private readonly IDeviceActionService _deviceActionService;
private readonly ILockService _lockService;
// TODO: Model binding context?
@@ -31,7 +32,8 @@ namespace Bit.App.Pages
_fingerprint = Resolver.Resolve<IFingerprint>();
_pushNotification = Resolver.Resolve<IPushNotificationService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_lockService = Resolver.Resolve<ILockService>();
Init();
}
@@ -327,22 +329,7 @@ namespace Bit.App.Pages
private void RateCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("OpenedSetting", "RateApp");
if(Device.RuntimePlatform == Device.iOS)
{
if(_deviceInfoService.Version < 11)
{
Device.OpenUri(new Uri("itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews" +
"?id=1137397744&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software"));
}
else
{
Device.OpenUri(new Uri("itms-apps://itunes.apple.com/us/app/id1137397744?action=write-review"));
}
}
else if(Device.RuntimePlatform == Device.Android)
{
MessagingCenter.Send(Application.Current, "RateApp");
}
_deviceActionService.RateApp();
}
private void HelpCell_Tapped(object sender, EventArgs e)
@@ -353,7 +340,7 @@ namespace Bit.App.Pages
private void LockCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("Locked");
MessagingCenter.Send(Application.Current, "Lock", true);
Device.BeginInvokeOnMainThread(async () => await _lockService.CheckLockAsync(true));
}
private async void LogOutCell_Tapped(object sender, EventArgs e)
@@ -363,7 +350,7 @@ namespace Bit.App.Pages
return;
}
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
private async void ChangeMasterPasswordCell_Tapped(object sender, EventArgs e)

View File

@@ -12,12 +12,14 @@ namespace Bit.App.Pages
{
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IAppInfoService _appInfoService;
private readonly IDeviceActionService _deviceActionService;
private bool _pageDisappeared = false;
public ToolsAutofillServicePage()
{
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_appInfoService = Resolver.Resolve<IAppInfoService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
Init();
}
@@ -221,7 +223,7 @@ namespace Bit.App.Pages
Command = new Command(() =>
{
_googleAnalyticsService.TrackAppEvent("OpenAccessibilitySettings");
MessagingCenter.Send(Application.Current, "Accessibility");
_deviceActionService.OpenAccessibilitySettings();
}),
VerticalOptions = LayoutOptions.End,
HorizontalOptions = LayoutOptions.Fill,

View File

@@ -29,6 +29,7 @@ namespace Bit.App.Pages
private readonly ISettings _settings;
private readonly IAppInfoService _appInfoService;
private readonly IDeviceInfoService _deviceInfo;
private readonly IDeviceActionService _deviceActionService;
private readonly string _defaultUri;
private readonly string _defaultName;
private readonly string _defaultUsername;
@@ -75,6 +76,7 @@ namespace Bit.App.Pages
_settings = Resolver.Resolve<ISettings>();
_appInfoService = Resolver.Resolve<IAppInfoService>();
_deviceInfo = Resolver.Resolve<IDeviceInfoService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
if(doInit)
{
@@ -751,7 +753,7 @@ namespace Bit.App.Pages
if(_fromAutofillFramework)
{
// close and go back to app
MessagingCenter.Send(Application.Current, "Autofill", (VaultListPageModel.Cipher)null);
_deviceActionService.CloseAutofill();
}
else
{

View File

@@ -20,7 +20,7 @@ namespace Bit.App.Pages
{
private readonly ICipherService _cipherService;
private readonly IDeviceInfoService _deviceInfoService;
private readonly IDeviceActionService _clipboardService;
private readonly IDeviceActionService _deviceActionService;
private readonly ISettingsService _settingsService;
private readonly IAppSettingsService _appSettingsService;
private CancellationTokenSource _filterResultsCancellationTokenSource;
@@ -44,7 +44,7 @@ namespace Bit.App.Pages
_cipherService = Resolver.Resolve<ICipherService>();
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
_clipboardService = Resolver.Resolve<IDeviceActionService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_settingsService = Resolver.Resolve<ISettingsService>();
UserDialogs = Resolver.Resolve<IUserDialogs>();
_appSettingsService = Resolver.Resolve<IAppSettingsService>();
@@ -141,7 +141,7 @@ namespace Bit.App.Pages
protected override bool OnBackButtonPressed()
{
GoogleAnalyticsService.TrackExtensionEvent("BackClosed", Uri.StartsWith("http") ? "Website" : "App");
MessagingCenter.Send(Application.Current, "Autofill", (VaultListPageModel.Cipher)null);
_deviceActionService.CloseAutofill();
return true;
}
@@ -243,7 +243,7 @@ namespace Bit.App.Pages
if(doAutofill)
{
GoogleAnalyticsService.TrackExtensionEvent("AutoFilled", Uri.StartsWith("http") ? "Website" : "App");
MessagingCenter.Send(Application.Current, "Autofill", cipher as VaultListPageModel.Cipher);
_deviceActionService.Autofill(cipher);
}
}
@@ -322,7 +322,7 @@ namespace Bit.App.Pages
private void Copy(string copyText, string alertLabel)
{
_clipboardService.CopyToClipboard(copyText);
_deviceActionService.CopyToClipboard(copyText);
UserDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
}

View File

@@ -24,7 +24,7 @@ namespace Bit.App.Pages
private readonly ICipherService _cipherService;
private readonly IUserDialogs _userDialogs;
private readonly IConnectivity _connectivity;
private readonly IDeviceActionService _clipboardService;
private readonly IDeviceActionService _deviceActionService;
private readonly ISyncService _syncService;
private readonly IPushNotificationService _pushNotification;
private readonly IDeviceInfoService _deviceInfoService;
@@ -42,7 +42,7 @@ namespace Bit.App.Pages
_cipherService = Resolver.Resolve<ICipherService>();
_connectivity = Resolver.Resolve<IConnectivity>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_clipboardService = Resolver.Resolve<IDeviceActionService>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_syncService = Resolver.Resolve<ISyncService>();
_pushNotification = Resolver.Resolve<IPushNotificationService>();
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
@@ -71,14 +71,6 @@ namespace Bit.App.Pages
private void Init()
{
MessagingCenter.Subscribe<Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
{
if(success)
{
_filterResultsCancellationTokenSource = FetchAndLoadVault();
}
});
if(!_favorites)
{
AddCipherItem = new AddCipherToolBarItem(this);
@@ -232,6 +224,14 @@ namespace Bit.App.Pages
protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Subscribe<ISyncService, bool>(_syncService, "SyncCompleted", (sender, success) =>
{
if(success)
{
_filterResultsCancellationTokenSource = FetchAndLoadVault();
}
});
ListView.ItemSelected += CipherSelected;
Search.TextChanged += SearchBar_TextChanged;
Search.SearchButtonPressed += SearchBar_SearchButtonPressed;
@@ -274,6 +274,8 @@ namespace Bit.App.Pages
protected override void OnDisappearing()
{
base.OnDisappearing();
MessagingCenter.Unsubscribe<ISyncService, bool>(_syncService, "SyncCompleted");
ListView.ItemSelected -= CipherSelected;
Search.TextChanged -= SearchBar_TextChanged;
Search.SearchButtonPressed -= SearchBar_SearchButtonPressed;
@@ -288,7 +290,7 @@ namespace Bit.App.Pages
}
_googleAnalyticsService.TrackExtensionEvent("BackClosed", Uri.StartsWith("http") ? "Website" : "App");
MessagingCenter.Send(Application.Current, "Autofill", (VaultListPageModel.Cipher)null);
_deviceActionService.CloseAutofill();
return true;
}
@@ -417,7 +419,7 @@ namespace Bit.App.Pages
{
_googleAnalyticsService.TrackExtensionEvent("AutoFilled",
Uri.StartsWith("http") ? "Website" : "App");
MessagingCenter.Send(Application.Current, "Autofill", cipher);
_deviceActionService.Autofill(cipher);
}
}
@@ -492,7 +494,7 @@ namespace Bit.App.Pages
private void Copy(string copyText, string alertLabel)
{
_clipboardService.CopyToClipboard(copyText);
_deviceActionService.CopyToClipboard(copyText);
_userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
}

View File

@@ -136,7 +136,7 @@ namespace Bit.App.Pages
{
if(Device.RuntimePlatform == Device.Android && Model.LoginUri.StartsWith("androidapp://"))
{
MessagingCenter.Send(Application.Current, "LaunchApp", Model.LoginUri);
_deviceActionService.LaunchApp(Model.LoginUri);
}
else if(Model.LoginUri.StartsWith("http://") || Model.LoginUri.StartsWith("https://"))
{

View File

@@ -7,6 +7,10 @@ using Plugin.Settings.Abstractions;
using Bit.App.Models;
using System.Linq;
using Bit.App.Enums;
using Xamarin.Forms;
using Bit.App.Pages;
using Bit.App.Controls;
using Acr.UserDialogs;
namespace Bit.App.Services
{
@@ -25,6 +29,9 @@ namespace Bit.App.Services
private readonly IAccountsApiRepository _accountsApiRepository;
private readonly IAppIdService _appIdService;
private readonly IDeviceInfoService _deviceInfoService;
private readonly IDeviceApiRepository _deviceApiRepository;
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IUserDialogs _userDialogs;
private string _email;
private string _userId;
@@ -39,7 +46,10 @@ namespace Bit.App.Services
IConnectApiRepository connectApiRepository,
IAccountsApiRepository accountsApiRepository,
IAppIdService appIdService,
IDeviceInfoService deviceInfoService)
IDeviceInfoService deviceInfoService,
IDeviceApiRepository deviceApiRepository,
IGoogleAnalyticsService googleAnalyticsService,
IUserDialogs userDialogs)
{
_secureStorage = secureStorage;
_tokenService = tokenService;
@@ -49,6 +59,9 @@ namespace Bit.App.Services
_accountsApiRepository = accountsApiRepository;
_appIdService = appIdService;
_deviceInfoService = deviceInfoService;
_deviceApiRepository = deviceApiRepository;
_googleAnalyticsService = googleAnalyticsService;
_userDialogs = userDialogs;
}
public string UserId
@@ -194,7 +207,7 @@ namespace Bit.App.Services
return !string.IsNullOrWhiteSpace(orgId) && (_cryptoService.OrgKeys?.ContainsKey(orgId) ?? false);
}
public void LogOut()
public void LogOut(string logoutMessage = null)
{
_tokenService.Token = null;
_tokenService.RefreshToken = null;
@@ -204,6 +217,16 @@ namespace Bit.App.Services
_settings.Remove(Constants.SecurityStamp);
_settings.Remove(Constants.PushLastRegistrationDate);
_settings.Remove(Constants.Locked);
Task.Run(async () => await _deviceApiRepository.PutClearTokenAsync(_appIdService.AppId));
_googleAnalyticsService.TrackAppEvent("LoggedOut");
Device.BeginInvokeOnMainThread(() => Application.Current.MainPage = new ExtendedNavigationPage(new HomePage()));
if(!string.IsNullOrWhiteSpace(logoutMessage))
{
_userDialogs.Toast(logoutMessage);
}
}
public async Task<FullLoginResult> TokenPostAsync(string email, string masterPassword)
@@ -249,10 +272,10 @@ namespace Bit.App.Services
return result;
}
public async Task<LoginResult> TokenPostTwoFactorAsync(TwoFactorProviderType type, string token, bool remember,
public async Task<Models.LoginResult> TokenPostTwoFactorAsync(TwoFactorProviderType type, string token, bool remember,
string email, string masterPasswordHash, SymmetricCryptoKey key)
{
var result = new LoginResult();
var result = new Models.LoginResult();
var request = new TokenRequest
{

View File

@@ -250,7 +250,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;
@@ -272,7 +272,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;
@@ -334,7 +334,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;
@@ -359,7 +359,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;

View File

@@ -75,7 +75,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;
@@ -91,7 +91,7 @@ namespace Bit.App.Services
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return response;

View File

@@ -4,6 +4,10 @@ using Plugin.Settings.Abstractions;
using Plugin.Fingerprint.Abstractions;
using Bit.App.Enums;
using System.Threading.Tasks;
using Bit.App.Controls;
using Bit.App.Pages;
using Xamarin.Forms;
using System.Linq;
namespace Bit.App.Services
{
@@ -79,5 +83,58 @@ namespace Bit.App.Services
return LockType.Password;
}
}
public async Task CheckLockAsync(bool forceLock)
{
if(TopPageIsLock())
{
// already locked
return;
}
var lockType = await GetLockTypeAsync(forceLock);
if(lockType == LockType.None)
{
return;
}
_appSettings.Locked = true;
switch(lockType)
{
case LockType.Fingerprint:
await Application.Current.MainPage.Navigation.PushModalAsync(
new ExtendedNavigationPage(new LockFingerprintPage(!forceLock)), false);
break;
case LockType.PIN:
await Application.Current.MainPage.Navigation.PushModalAsync(
new ExtendedNavigationPage(new LockPinPage()), false);
break;
case LockType.Password:
await Application.Current.MainPage.Navigation.PushModalAsync(
new ExtendedNavigationPage(new LockPasswordPage()), false);
break;
default:
break;
}
}
public bool TopPageIsLock()
{
var currentPage = Application.Current.MainPage.Navigation.ModalStack.LastOrDefault() as ExtendedNavigationPage;
if((currentPage?.CurrentPage as LockFingerprintPage) != null)
{
return true;
}
if((currentPage?.CurrentPage as LockPinPage) != null)
{
return true;
}
if((currentPage?.CurrentPage as LockPasswordPage) != null)
{
return true;
}
return false;
}
}
}

View File

@@ -305,7 +305,7 @@ namespace Bit.App.Services
if(Application.Current != null && (accountRevisionDate.StatusCode == System.Net.HttpStatusCode.Forbidden
|| accountRevisionDate.StatusCode == System.Net.HttpStatusCode.Unauthorized))
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return false;
@@ -477,7 +477,7 @@ namespace Bit.App.Services
}
SyncInProgress = true;
MessagingCenter.Send(Application.Current, "SyncStarted");
MessagingCenter.Send(this, "SyncStarted");
}
private void SyncCompleted(bool successfully)
@@ -488,7 +488,7 @@ namespace Bit.App.Services
}
SyncInProgress = false;
MessagingCenter.Send(Application.Current, "SyncCompleted", successfully);
MessagingCenter.Send(this, "SyncCompleted", successfully);
}
private bool CheckSuccess<T>(ApiResult<T> result, bool logout = false)
@@ -501,7 +501,7 @@ namespace Bit.App.Services
result.StatusCode == System.Net.HttpStatusCode.Forbidden ||
result.StatusCode == System.Net.HttpStatusCode.Unauthorized))
{
MessagingCenter.Send(Application.Current, "Logout", (string)null);
_authService.LogOut();
}
return false;