mirror of
https://github.com/bitwarden/mobile
synced 2025-12-13 23:03:23 +00:00
[Auto Logout] Final review of feature (#932)
* Initial commit of LockService name refactor (#831) * [Auto-Logout] Update Service layer logic (#835) * Initial commit of service logic update * Added default value for action * Updated ToggleTokensAsync conditional * Removed unused variables, updated action conditional * Initial commit: lockOption/lock refactor app layer (#840) * [Auto-Logout] Settings Refactor - Application Layer Part 2 (#844) * Initial commit of app layer part 2 * Updated biometrics position * Reverted resource name refactor * LockOptions refactor revert * Updated method casing :: Removed VaultTimeout prefix for timeouts * Fixed dupe string resource (#854) * Updated dependency to use VaultTimeoutService (#896) * [Auto Logout] Xamarin Forms in AutoFill flow (iOS) (#902) * fix typo in PINRequireMasterPasswordRestart (#900) * initial commit for xf usage in autofill * Fixed databinding for hint button * Updated Two Factor page launch - removed unused imports * First pass at broadcast/messenger implentation for autofill * setting theme in extension using theme manager * extension app resources * App resources from main app * fix ref to twoFactorPage * apply resources to page * load empty app for sytling in extension * move ios renderers to ios core * static ref to resources and GetResourceColor helper * fix method ref * move application.current.resources refs to helper * switch login page alerts to device action dialogs * run on main thread * showDialog with device action service * abstract action sheet to device action service * add support for yubikey * add yubikey iimages to extension * support close button action * add support to action extension * remove empty lines Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * [Auto Logout] Update lock option to be default value (#929) * Initial commit - make lock action default * Removed extra whitespace Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Bit.App.Pages
|
||||
private readonly IDeviceActionService _deviceActionService;
|
||||
private readonly IEnvironmentService _environmentService;
|
||||
private readonly IMessagingService _messagingService;
|
||||
private readonly ILockService _lockService;
|
||||
private readonly IVaultTimeoutService _vaultTimeoutService;
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly ISyncService _syncService;
|
||||
|
||||
@@ -27,20 +27,27 @@ namespace Bit.App.Pages
|
||||
private bool _pin;
|
||||
private bool _fingerprint;
|
||||
private string _lastSyncDate;
|
||||
private string _lockOptionValue;
|
||||
private List<KeyValuePair<string, int?>> _lockOptions =
|
||||
private string _vaultTimeoutDisplayValue;
|
||||
private string _vaultTimeoutActionDisplayValue;
|
||||
private List<KeyValuePair<string, int?>> _vaultTimeouts =
|
||||
new List<KeyValuePair<string, int?>>
|
||||
{
|
||||
new KeyValuePair<string, int?>(AppResources.LockOptionImmediately, 0),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption1Minute, 1),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption5Minutes, 5),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption15Minutes, 15),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption30Minutes, 30),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption1Hour, 60),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOption4Hours, 240),
|
||||
new KeyValuePair<string, int?>(AppResources.LockOptionOnRestart, -1),
|
||||
new KeyValuePair<string, int?>(AppResources.Immediately, 0),
|
||||
new KeyValuePair<string, int?>(AppResources.OneMinute, 1),
|
||||
new KeyValuePair<string, int?>(AppResources.FiveMinutes, 5),
|
||||
new KeyValuePair<string, int?>(AppResources.FifteenMinutes, 15),
|
||||
new KeyValuePair<string, int?>(AppResources.ThirtyMinutes, 30),
|
||||
new KeyValuePair<string, int?>(AppResources.OneHour, 60),
|
||||
new KeyValuePair<string, int?>(AppResources.FourHours, 240),
|
||||
new KeyValuePair<string, int?>(AppResources.OnRestart, -1),
|
||||
new KeyValuePair<string, int?>(AppResources.Never, null),
|
||||
};
|
||||
private List<KeyValuePair<string, string>> _vaultTimeoutActions =
|
||||
new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>(AppResources.Lock, "lock"),
|
||||
new KeyValuePair<string, string>(AppResources.LogOut, "logOut"),
|
||||
};
|
||||
|
||||
public SettingsPageViewModel()
|
||||
{
|
||||
@@ -50,7 +57,7 @@ namespace Bit.App.Pages
|
||||
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||
_environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService");
|
||||
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
||||
_lockService = ServiceContainer.Resolve<ILockService>("lockService");
|
||||
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
||||
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
||||
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
||||
|
||||
@@ -70,11 +77,13 @@ namespace Bit.App.Pages
|
||||
_lastSyncDate = string.Format("{0} {1}", lastSync.Value.ToShortDateString(),
|
||||
lastSync.Value.ToShortTimeString());
|
||||
}
|
||||
var option = await _storageService.GetAsync<int?>(Constants.LockOptionKey);
|
||||
_lockOptionValue = _lockOptions.FirstOrDefault(o => o.Value == option).Key;
|
||||
var pinSet = await _lockService.IsPinLockSetAsync();
|
||||
var timeout = await _storageService.GetAsync<int?>(Constants.VaultTimeoutKey);
|
||||
_vaultTimeoutDisplayValue = _vaultTimeouts.FirstOrDefault(o => o.Value == timeout).Key;
|
||||
var action = await _storageService.GetAsync<string>(Constants.VaultTimeoutActionKey) ?? "lock";
|
||||
_vaultTimeoutActionDisplayValue = _vaultTimeoutActions.FirstOrDefault(o => o.Value == action).Key;
|
||||
var pinSet = await _vaultTimeoutService.IsPinLockSetAsync();
|
||||
_pin = pinSet.Item1 || pinSet.Item2;
|
||||
_fingerprint = await _lockService.IsFingerprintLockSetAsync();
|
||||
_fingerprint = await _vaultTimeoutService.IsFingerprintLockSetAsync();
|
||||
BuildList();
|
||||
}
|
||||
|
||||
@@ -179,21 +188,48 @@ namespace Bit.App.Pages
|
||||
|
||||
public async Task LockAsync()
|
||||
{
|
||||
await _lockService.LockAsync(true, true);
|
||||
await _vaultTimeoutService.LockAsync(true, true);
|
||||
}
|
||||
|
||||
public async Task LockOptionsAsync()
|
||||
public async Task VaultTimeoutAsync()
|
||||
{
|
||||
var options = _lockOptions.Select(o => o.Key == _lockOptionValue ? $"✓ {o.Key}" : o.Key).ToArray();
|
||||
var selection = await Page.DisplayActionSheet(AppResources.LockOptions, AppResources.Cancel, null, options);
|
||||
var options = _vaultTimeouts.Select(o => o.Key == _vaultTimeoutDisplayValue ? $"✓ {o.Key}" : o.Key).ToArray();
|
||||
var selection = await Page.DisplayActionSheet(AppResources.VaultTimeout, AppResources.Cancel, null, options);
|
||||
if (selection == null || selection == AppResources.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var cleanSelection = selection.Replace("✓ ", string.Empty);
|
||||
var selectionOption = _lockOptions.FirstOrDefault(o => o.Key == cleanSelection);
|
||||
_lockOptionValue = selectionOption.Key;
|
||||
await _lockService.SetLockOptionAsync(selectionOption.Value);
|
||||
var selectionOption = _vaultTimeouts.FirstOrDefault(o => o.Key == cleanSelection);
|
||||
_vaultTimeoutDisplayValue = selectionOption.Key;
|
||||
await _vaultTimeoutService.SetVaultTimeoutOptionsAsync(selectionOption.Value,
|
||||
GetVaultTimeoutActionFromKey(_vaultTimeoutActionDisplayValue));
|
||||
BuildList();
|
||||
}
|
||||
|
||||
public async Task VaultTimeoutActionAsync()
|
||||
{
|
||||
var options = _vaultTimeoutActions.Select(o => o.Key == _vaultTimeoutActionDisplayValue ? $"✓ {o.Key}" : o.Key).ToArray();
|
||||
var selection = await Page.DisplayActionSheet(AppResources.VaultTimeoutAction, AppResources.Cancel, null, options);
|
||||
if (selection == null || selection == AppResources.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var cleanSelection = selection.Replace("✓ ", string.Empty);
|
||||
if (cleanSelection == AppResources.LogOut)
|
||||
{
|
||||
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.VaultTimeoutLogOutConfirmation,
|
||||
AppResources.Warning, AppResources.Yes, AppResources.Cancel);
|
||||
if (!confirmed)
|
||||
{
|
||||
// Reset to lock and continue process as if lock were selected
|
||||
cleanSelection = AppResources.Lock;
|
||||
}
|
||||
}
|
||||
var selectionOption = _vaultTimeoutActions.FirstOrDefault(o => o.Key == cleanSelection);
|
||||
_vaultTimeoutActionDisplayValue = selectionOption.Key;
|
||||
await _vaultTimeoutService.SetVaultTimeoutOptionsAsync(GetVaultTimeoutFromKey(_vaultTimeoutDisplayValue),
|
||||
selectionOption.Value);
|
||||
BuildList();
|
||||
}
|
||||
|
||||
@@ -223,7 +259,7 @@ namespace Bit.App.Pages
|
||||
{
|
||||
var encPin = await _cryptoService.EncryptAsync(pin);
|
||||
await _storageService.SaveAsync(Constants.ProtectedPin, encPin.EncryptedString);
|
||||
_lockService.PinProtectedKey = pinProtectedKey;
|
||||
_vaultTimeoutService.PinProtectedKey = pinProtectedKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -238,7 +274,7 @@ namespace Bit.App.Pages
|
||||
if (!_pin)
|
||||
{
|
||||
await _cryptoService.ClearPinProtectedKeyAsync();
|
||||
await _lockService.ClearAsync();
|
||||
await _vaultTimeoutService.ClearAsync();
|
||||
}
|
||||
BuildList();
|
||||
}
|
||||
@@ -267,7 +303,7 @@ namespace Bit.App.Pages
|
||||
{
|
||||
await _storageService.RemoveAsync(Constants.FingerprintUnlockKey);
|
||||
}
|
||||
_lockService.FingerprintLocked = false;
|
||||
_vaultTimeoutService.FingerprintLocked = false;
|
||||
await _cryptoService.ToggleKeyAsync();
|
||||
BuildList();
|
||||
}
|
||||
@@ -312,7 +348,8 @@ namespace Bit.App.Pages
|
||||
};
|
||||
var securityItems = new List<SettingsPageListItem>
|
||||
{
|
||||
new SettingsPageListItem { Name = AppResources.LockOptions, SubLabel = _lockOptionValue },
|
||||
new SettingsPageListItem { Name = AppResources.VaultTimeout, SubLabel = _vaultTimeoutDisplayValue },
|
||||
new SettingsPageListItem { Name = AppResources.VaultTimeoutAction, SubLabel = _vaultTimeoutActionDisplayValue },
|
||||
new SettingsPageListItem
|
||||
{
|
||||
Name = AppResources.UnlockWithPIN,
|
||||
@@ -338,7 +375,7 @@ namespace Bit.App.Pages
|
||||
Name = string.Format(AppResources.UnlockWith, fingerprintName),
|
||||
SubLabel = _fingerprint ? AppResources.Enabled : AppResources.Disabled
|
||||
};
|
||||
securityItems.Insert(1, item);
|
||||
securityItems.Insert(2, item);
|
||||
}
|
||||
var accountItems = new List<SettingsPageListItem>
|
||||
{
|
||||
@@ -370,5 +407,15 @@ namespace Bit.App.Pages
|
||||
new SettingsPageListGroup(otherItems, AppResources.Other, doUpper)
|
||||
});
|
||||
}
|
||||
|
||||
private string GetVaultTimeoutActionFromKey(string key)
|
||||
{
|
||||
return _vaultTimeoutActions.FirstOrDefault(o => o.Key == key).Value;
|
||||
}
|
||||
|
||||
private int? GetVaultTimeoutFromKey(string key)
|
||||
{
|
||||
return _vaultTimeouts.FirstOrDefault(o => o.Key == key).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user