From bc6ff3e3bc1f128b454b371aea5f19ce02953d05 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 20 May 2017 12:36:09 -0400 Subject: [PATCH] prevent rapid clicking actions that crash app --- src/App/Pages/HomePage.cs | 13 +++++++++++++ src/App/Pages/Lock/LockFingerprintPage.cs | 7 +++++++ src/App/Pages/Lock/LockPasswordPage.cs | 7 +++++++ src/App/Pages/Lock/LockPinPage.cs | 7 +++++++ src/App/Pages/Settings/SettingsAddFolderPage.cs | 7 +++++++ src/App/Pages/Settings/SettingsEditFolderPage.cs | 7 +++++++ src/App/Pages/Vault/VaultAddLoginPage.cs | 7 +++++++ src/App/Pages/Vault/VaultEditLoginPage.cs | 7 +++++++ src/App/Utilities/Extentions.cs | 11 +++++++++++ 9 files changed, 73 insertions(+) diff --git a/src/App/Pages/HomePage.cs b/src/App/Pages/HomePage.cs index 4ea00d4da..c5086cf0e 100644 --- a/src/App/Pages/HomePage.cs +++ b/src/App/Pages/HomePage.cs @@ -16,6 +16,7 @@ namespace Bit.App.Pages private readonly IAuthService _authService; private readonly IUserDialogs _userDialogs; private readonly ISettings _settings; + private DateTime? _lastAction; public HomePage() : base(updateActivity: false) @@ -92,11 +93,23 @@ namespace Bit.App.Pages public async Task LoginAsync() { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + await Navigation.PushForDeviceAsync(new LoginPage()); } public async Task RegisterAsync() { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + await Navigation.PushForDeviceAsync(new RegisterPage(this)); } diff --git a/src/App/Pages/Lock/LockFingerprintPage.cs b/src/App/Pages/Lock/LockFingerprintPage.cs index 955b3f9e8..ed541d9ed 100644 --- a/src/App/Pages/Lock/LockFingerprintPage.cs +++ b/src/App/Pages/Lock/LockFingerprintPage.cs @@ -16,6 +16,7 @@ namespace Bit.App.Pages private readonly ISettings _settings; private readonly IAppSettingsService _appSettings; private readonly bool _checkFingerprintImmediately; + private DateTime? _lastAction; public LockFingerprintPage(bool checkFingerprintImmediately) { @@ -79,6 +80,12 @@ namespace Bit.App.Pages public async Task CheckFingerprintAsync() { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + var result = await _fingerprint.AuthenticateAsync(AppResources.FingerprintDirection); if(result.Authenticated) { diff --git a/src/App/Pages/Lock/LockPasswordPage.cs b/src/App/Pages/Lock/LockPasswordPage.cs index 7c863df5f..d89d50329 100644 --- a/src/App/Pages/Lock/LockPasswordPage.cs +++ b/src/App/Pages/Lock/LockPasswordPage.cs @@ -14,6 +14,7 @@ namespace Bit.App.Pages private readonly IAuthService _authService; private readonly IAppSettingsService _appSettingsService; private readonly ICryptoService _cryptoService; + private DateTime? _lastAction; public LockPasswordPage() { @@ -111,6 +112,12 @@ namespace Bit.App.Pages protected async Task CheckPasswordAsync() { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, diff --git a/src/App/Pages/Lock/LockPinPage.cs b/src/App/Pages/Lock/LockPinPage.cs index 66021f692..4cd6cd5ce 100644 --- a/src/App/Pages/Lock/LockPinPage.cs +++ b/src/App/Pages/Lock/LockPinPage.cs @@ -13,6 +13,7 @@ namespace Bit.App.Pages private readonly IAuthService _authService; private readonly IAppSettingsService _appSettingsService; private TapGestureRecognizer _tgr; + private DateTime? _lastAction; public LockPinPage() { @@ -91,6 +92,12 @@ namespace Bit.App.Pages protected void PinEntered(object sender, EventArgs args) { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(Model.PIN == _authService.PIN) { _appSettingsService.Locked = false; diff --git a/src/App/Pages/Settings/SettingsAddFolderPage.cs b/src/App/Pages/Settings/SettingsAddFolderPage.cs index e0472e86e..ea93c2f24 100644 --- a/src/App/Pages/Settings/SettingsAddFolderPage.cs +++ b/src/App/Pages/Settings/SettingsAddFolderPage.cs @@ -17,6 +17,7 @@ namespace Bit.App.Pages private readonly IUserDialogs _userDialogs; private readonly IConnectivity _connectivity; private readonly IGoogleAnalyticsService _googleAnalyticsService; + private DateTime? _lastAction; public SettingsAddFolderPage() { @@ -56,6 +57,12 @@ namespace Bit.App.Pages var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () => { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Pages/Settings/SettingsEditFolderPage.cs b/src/App/Pages/Settings/SettingsEditFolderPage.cs index c23644999..ec77aa0cb 100644 --- a/src/App/Pages/Settings/SettingsEditFolderPage.cs +++ b/src/App/Pages/Settings/SettingsEditFolderPage.cs @@ -17,6 +17,7 @@ namespace Bit.App.Pages private readonly IUserDialogs _userDialogs; private readonly IConnectivity _connectivity; private readonly IGoogleAnalyticsService _googleAnalyticsService; + private DateTime? _lastAction; public SettingsEditFolderPage(string folderId) { @@ -73,6 +74,12 @@ namespace Bit.App.Pages var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () => { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Pages/Vault/VaultAddLoginPage.cs b/src/App/Pages/Vault/VaultAddLoginPage.cs index de4ee0bfb..0771e2978 100644 --- a/src/App/Pages/Vault/VaultAddLoginPage.cs +++ b/src/App/Pages/Vault/VaultAddLoginPage.cs @@ -27,6 +27,7 @@ namespace Bit.App.Pages private readonly string _defaultUri; private readonly string _defaultName; private readonly bool _fromAutofill; + private DateTime? _lastAction; public VaultAddLoginPage(string defaultUri = null, string defaultName = null, bool fromAutofill = false) { @@ -135,6 +136,12 @@ namespace Bit.App.Pages var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () => { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Pages/Vault/VaultEditLoginPage.cs b/src/App/Pages/Vault/VaultEditLoginPage.cs index f0835d89b..4d3526692 100644 --- a/src/App/Pages/Vault/VaultEditLoginPage.cs +++ b/src/App/Pages/Vault/VaultEditLoginPage.cs @@ -19,6 +19,7 @@ namespace Bit.App.Pages private readonly IUserDialogs _userDialogs; private readonly IConnectivity _connectivity; private readonly IGoogleAnalyticsService _googleAnalyticsService; + private DateTime? _lastAction; public VaultEditLoginPage(string loginId) { @@ -146,6 +147,12 @@ namespace Bit.App.Pages var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () => { + if(_lastAction.LastActionWasRecent()) + { + return; + } + _lastAction = DateTime.UtcNow; + if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Utilities/Extentions.cs b/src/App/Utilities/Extentions.cs index 059dc3d4a..2c9f0bf13 100644 --- a/src/App/Utilities/Extentions.cs +++ b/src/App/Utilities/Extentions.cs @@ -106,5 +106,16 @@ namespace Bit.App } } } + + public static bool LastActionWasRecent(this DateTime? lastAction, int milliseconds = 1000) + { + if(lastAction.HasValue && (DateTime.UtcNow - lastAction.Value).TotalMilliseconds < milliseconds) + { + System.Diagnostics.Debug.WriteLine("Last action occurred recently."); + return true; + } + + return false; + } } }