1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-26 10:36:21 +02:00

Added "first load" check on site list to wait for sync to complete if key changed. Renamed "other" constants.

This commit is contained in:
Kyle Spearrin 2016-08-05 23:58:31 -04:00
parent d96a94b478
commit 38184e4893
18 changed files with 54 additions and 26 deletions

View File

@ -98,7 +98,7 @@ namespace Bit.App
if(Device.OS == TargetPlatform.Android)
{
_settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
_settings.AddOrUpdateValue(Constants.LastBackgroundedDate, DateTime.UtcNow);
}
}

View File

@ -5,10 +5,6 @@
public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn";
public const string SettingPinUnlockOn = "setting:pinUnlockOn";
public const string SettingLockSeconds = "setting:lockSeconds";
public const string SettingLastBackgroundedDate = "lastBackgroundedDate";
public const string SettingLocked = "locked";
public const string SettingLastLoginEmail = "lastLoginEmail";
public const string SettingLastSync = "lastSync";
public const string PasswordGeneratorLength = "pwGenerator:length";
public const string PasswordGeneratorUppercase = "pwGenerator:uppercase";
@ -24,5 +20,11 @@
public const string ExtensionStarted = "extension:started";
public const string ExtensionActivated = "extension:activated";
public const string FirstVaultLoad = "other:firstVaultLoad";
public const string LastBackgroundedDate = "other:lastBackgroundedDate";
public const string Locked = "other:locked";
public const string LastLoginEmail = "other:lastLoginEmail";
public const string LastSync = "other:lastSync";
}
}

View File

@ -97,7 +97,7 @@ namespace Bit.App.Pages
var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify.");
if(result.Authenticated)
{
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
await Navigation.PopModalAsync();
}
else if(result.Status == FingerprintAuthenticationResultStatus.FallbackRequested)

View File

@ -107,7 +107,7 @@ namespace Bit.App.Pages
var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, _authService.Email);
if(key.SequenceEqual(_cryptoService.Key))
{
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
await Navigation.PopModalAsync();
}
else

View File

@ -92,7 +92,7 @@ namespace Bit.App.Pages
{
if(Model.PIN == _authService.PIN)
{
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
PinControl.Entry.Unfocus();
Navigation.PopModalAsync();
}

View File

@ -53,7 +53,7 @@ namespace Bit.App.Pages
entryKeyboard: Keyboard.Email, useLabelAsPlaceholder: true, imageSource: "envelope",
containerPadding: padding);
var lastLoginEmail = _settings.GetValueOrDefault<string>(Constants.SettingLastLoginEmail);
var lastLoginEmail = _settings.GetValueOrDefault<string>(Constants.LastLoginEmail);
if(!string.IsNullOrWhiteSpace(lastLoginEmail))
{
EmailCell.Entry.Text = lastLoginEmail;
@ -179,7 +179,7 @@ namespace Bit.App.Pages
_authService.Token = response.Result.Token;
_authService.UserId = response.Result?.Profile?.Id;
_authService.Email = response.Result?.Profile?.Email;
_settings.AddOrUpdateValue(Constants.SettingLastLoginEmail, _authService.Email);
_settings.AddOrUpdateValue(Constants.LastLoginEmail, _authService.Email);
_googleAnalyticsService.RefreshUserId();
_googleAnalyticsService.TrackAppEvent("LoggedIn");

View File

@ -256,7 +256,7 @@ namespace Bit.App.Pages
private void LockCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("Locked");
_settings.AddOrUpdateValue(Constants.SettingLocked, true);
_settings.AddOrUpdateValue(Constants.Locked, true);
MessagingCenter.Send(Application.Current, "Lock", true);
}

View File

@ -72,7 +72,7 @@ namespace Bit.App.Pages
private void SetLastSync()
{
var lastSyncDate = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
var lastSyncDate = _settings.GetValueOrDefault<DateTime?>(Constants.LastSync);
LastSyncLabel.Text = "Last Sync: " + lastSyncDate?.ToLocalTime().ToString() ?? "Never";
}

View File

@ -28,6 +28,7 @@ namespace Bit.App.Pages
private readonly IPushNotification _pushNotification;
private readonly ISettings _settings;
private readonly bool _favorites;
private bool _loadExistingData;
public VaultListSitesPage(bool favorites)
{
@ -41,6 +42,9 @@ namespace Bit.App.Pages
_pushNotification = Resolver.Resolve<IPushNotification>();
_settings = Resolver.Resolve<ISettings>();
var cryptoService = Resolver.Resolve<ICryptoService>();
_loadExistingData = !_settings.GetValueOrDefault(Constants.FirstVaultLoad, true) || !cryptoService.KeyChanged;
Init();
}
@ -150,7 +154,10 @@ namespace Bit.App.Pages
protected override void OnAppearing()
{
base.OnAppearing();
FetchAndLoadVault();
if(_loadExistingData)
{
FetchAndLoadVault();
}
if(_connectivity.IsConnected && Device.OS == TargetPlatform.iOS && !_favorites)
{
@ -181,12 +188,14 @@ namespace Bit.App.Pages
// Check push registration once per day
registerAction();
}
}
}
private void FetchAndLoadVault()
{
_settings.AddOrUpdateValue(Constants.FirstVaultLoad, false);
_loadExistingData = true;
if(PresentationFolders.Count > 0 && _syncService.SyncInProgress)
{
return;

View File

@ -206,6 +206,7 @@ namespace Bit.App.Services
UserId = null;
Email = null;
_cryptoService.Key = null;
_settings.Remove(Constants.FirstVaultLoad);
}
public async Task<ApiResult<TokenResponse>> TokenPostAsync(TokenRequest request)

View File

@ -88,7 +88,23 @@ namespace Bit.App.Services
}
}
public bool KeyChanged => !PreviousKey?.SequenceEqual(Key) ?? Key == null ? false : true;
public bool KeyChanged
{
get
{
if(Key == null)
{
throw new InvalidOperationException("Key must be set before asking if it has changed.");
}
if(PreviousKey == null)
{
return Key != null;
}
return !PreviousKey.SequenceEqual(Key);
}
}
public CipherString Encrypt(string plaintextValue)
{

View File

@ -31,7 +31,7 @@ namespace Bit.App.Services
}
// Are we forcing a lock? (i.e. clicking a button to lock the app manually, immediately)
if(!forceLock && !_settings.GetValueOrDefault(Constants.SettingLocked, false))
if(!forceLock && !_settings.GetValueOrDefault(Constants.Locked, false))
{
// Lock seconds tells if they want to lock the app or not
var lockSeconds = _settings.GetValueOrDefault(Constants.SettingLockSeconds, 60 * 15);
@ -42,7 +42,7 @@ namespace Bit.App.Services
// Has it been longer than lockSeconds since the last time the app was backgrounded?
var now = DateTime.UtcNow;
var lastBackground = _settings.GetValueOrDefault(Constants.SettingLastBackgroundedDate, now.AddYears(-1));
var lastBackground = _settings.GetValueOrDefault(Constants.LastBackgroundedDate, now.AddYears(-1));
if((now - lastBackground).TotalSeconds < lockSeconds)
{
return LockType.None;

View File

@ -160,14 +160,14 @@ namespace Bit.App.Services
return false;
}
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
_settings.AddOrUpdateValue(Constants.LastSync, now);
SyncCompleted(true);
return true;
}
public async Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold)
{
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.LastSync);
if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold)
{
return false;
@ -184,7 +184,7 @@ namespace Bit.App.Services
}
var now = DateTime.UtcNow;
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.LastSync);
if(lastSync == null)
{
return await FullSyncAsync();
@ -217,7 +217,7 @@ namespace Bit.App.Services
return false;
}
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
_settings.AddOrUpdateValue(Constants.LastSync, now);
SyncCompleted(true);
return true;
}

View File

@ -70,7 +70,7 @@ namespace Bit.iOS.Extension
var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify.");
if(result.Authenticated)
{
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
LoadingController.DismissLockAndContinue();
}
}

View File

@ -85,7 +85,7 @@ namespace Bit.iOS.Extension
var key = _cryptoService.MakeKeyFromPassword(MasterPasswordCell.TextField.Text, _authService.Email);
if(key.SequenceEqual(_cryptoService.Key))
{
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
MasterPasswordCell.TextField.ResignFirstResponder();
LoadingController.DismissLockAndContinue();
}

View File

@ -65,7 +65,7 @@ namespace Bit.iOS.Extension
if(PinTextField.Text == _authService.PIN)
{
Debug.WriteLine("BW Log, Start Dismiss PIN controller.");
_settings.AddOrUpdateValue(Constants.SettingLocked, false);
_settings.AddOrUpdateValue(Constants.Locked, false);
PinTextField.ResignFirstResponder();
LoadingController.DismissLockAndContinue();
}

View File

@ -174,7 +174,7 @@ namespace Bit.iOS.Extension
return;
}
Resolver.Resolve<ISettings>().AddOrUpdateValue(App.Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
Resolver.Resolve<ISettings>().AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow);
var item = _tableItems.ElementAt(indexPath.Row);
if(item == null)

View File

@ -141,7 +141,7 @@ namespace Bit.iOS
UIApplication.SharedApplication.SetStatusBarHidden(true, false);
// Log the date/time we last backgrounded
Settings.AddOrUpdateValue(App.Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
Settings.AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow);
// Dispatch Google Analytics
SendGoogleAnalyticsHitsInBackground();