2019-05-15 19:09:49 +02:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Resources;
|
2019-05-16 20:55:18 +02:00
|
|
|
|
using Bit.Core;
|
2019-05-15 15:14:49 +02:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
2019-05-14 15:09:35 +02:00
|
|
|
|
using System;
|
2019-03-29 04:52:33 +01:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-16 20:55:18 +02:00
|
|
|
|
using System.Linq;
|
2019-05-15 15:14:49 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2019-04-05 22:13:17 +02:00
|
|
|
|
using Xamarin.Forms;
|
2019-03-29 04:52:33 +01:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class SettingsPageViewModel : BaseViewModel
|
|
|
|
|
{
|
2019-05-15 15:14:49 +02:00
|
|
|
|
private readonly IPlatformUtilsService _platformUtilsService;
|
2019-05-15 18:54:48 +02:00
|
|
|
|
private readonly ICryptoService _cryptoService;
|
|
|
|
|
private readonly IUserService _userService;
|
2019-05-15 19:09:49 +02:00
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
2019-05-15 19:26:55 +02:00
|
|
|
|
private readonly IEnvironmentService _environmentService;
|
|
|
|
|
private readonly IMessagingService _messagingService;
|
2019-05-15 21:47:50 +02:00
|
|
|
|
private readonly ILockService _lockService;
|
2019-05-16 20:55:18 +02:00
|
|
|
|
private readonly IStorageService _storageService;
|
|
|
|
|
private readonly ISyncService _syncService;
|
|
|
|
|
|
|
|
|
|
private bool _pin;
|
|
|
|
|
private bool _fingerprint;
|
|
|
|
|
private string _lastSyncDate;
|
|
|
|
|
private string _lockOptionValue;
|
|
|
|
|
private List<KeyValuePair<string, int?>> _lockOptions =
|
|
|
|
|
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.Never, null),
|
|
|
|
|
};
|
2019-05-15 15:14:49 +02:00
|
|
|
|
|
2019-03-29 04:52:33 +01:00
|
|
|
|
public SettingsPageViewModel()
|
|
|
|
|
{
|
2019-05-15 15:14:49 +02:00
|
|
|
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
2019-05-15 18:54:48 +02:00
|
|
|
|
_cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
|
|
|
|
|
_userService = ServiceContainer.Resolve<IUserService>("userService");
|
2019-05-15 19:09:49 +02:00
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2019-05-15 19:26:55 +02:00
|
|
|
|
_environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService");
|
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
2019-05-15 21:47:50 +02:00
|
|
|
|
_lockService = ServiceContainer.Resolve<ILockService>("lockService");
|
2019-05-16 20:55:18 +02:00
|
|
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
|
|
|
|
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
2019-04-05 22:13:17 +02:00
|
|
|
|
|
2019-05-16 20:55:18 +02:00
|
|
|
|
GroupedItems = new ExtendedObservableCollection<SettingsPageListGroup>();
|
2019-05-15 15:14:49 +02:00
|
|
|
|
PageTitle = AppResources.Settings;
|
2019-03-29 04:52:33 +01:00
|
|
|
|
}
|
2019-04-05 22:13:17 +02:00
|
|
|
|
|
2019-05-16 20:55:18 +02:00
|
|
|
|
public ExtendedObservableCollection<SettingsPageListGroup> GroupedItems { get; set; }
|
|
|
|
|
|
|
|
|
|
public async Task InitAsync()
|
|
|
|
|
{
|
|
|
|
|
var lastSync = await _syncService.GetLastSyncAsync();
|
|
|
|
|
if(lastSync != null)
|
|
|
|
|
{
|
|
|
|
|
_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();
|
|
|
|
|
_pin = pinSet.Item1 || pinSet.Item2;
|
|
|
|
|
// TODO: Fingerprint
|
|
|
|
|
BuildList();
|
|
|
|
|
}
|
2019-05-14 17:53:41 +02:00
|
|
|
|
|
2019-05-15 15:14:49 +02:00
|
|
|
|
public async Task AboutAsync()
|
|
|
|
|
{
|
|
|
|
|
var debugText = string.Format("{0}: {1}", AppResources.Version,
|
|
|
|
|
_platformUtilsService.GetApplicationVersion());
|
|
|
|
|
var text = string.Format("© 8bit Solutions LLC 2015-{0}\n\n{1}", DateTime.Now.Year, debugText);
|
|
|
|
|
var copy = await _platformUtilsService.ShowDialogAsync(text, AppResources.Bitwarden, AppResources.Copy,
|
|
|
|
|
AppResources.Close);
|
|
|
|
|
if(copy)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.CopyToClipboardAsync(debugText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 18:54:48 +02:00
|
|
|
|
public void Help()
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task FingerprintAsync()
|
|
|
|
|
{
|
|
|
|
|
var fingerprint = await _cryptoService.GetFingerprintAsync(await _userService.GetUserIdAsync());
|
|
|
|
|
var phrase = string.Join("-", fingerprint);
|
2019-05-15 18:55:52 +02:00
|
|
|
|
var text = string.Format("{0}:\n\n{1}", AppResources.YourAccountsFingerprint, phrase);
|
2019-05-15 18:54:48 +02:00
|
|
|
|
var learnMore = await _platformUtilsService.ShowDialogAsync(text, AppResources.FingerprintPhrase,
|
|
|
|
|
AppResources.LearnMore, AppResources.Close);
|
|
|
|
|
if(learnMore)
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/fingerprint-phrase/");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-15 19:09:49 +02:00
|
|
|
|
|
|
|
|
|
public void Rate()
|
|
|
|
|
{
|
|
|
|
|
_deviceActionService.RateApp();
|
|
|
|
|
}
|
2019-05-15 18:54:48 +02:00
|
|
|
|
|
2019-05-15 19:26:55 +02:00
|
|
|
|
public void Import()
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/import-data/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Export()
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/export-your-data/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WebVault()
|
|
|
|
|
{
|
|
|
|
|
var url = _environmentService.GetWebVaultUrl();
|
|
|
|
|
if(url == null)
|
|
|
|
|
{
|
|
|
|
|
url = "https://vault.bitwarden.com";
|
|
|
|
|
}
|
|
|
|
|
_platformUtilsService.LaunchUri(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ShareAsync()
|
|
|
|
|
{
|
|
|
|
|
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.ShareVaultConfirmation,
|
|
|
|
|
AppResources.ShareVault, AppResources.Yes, AppResources.Cancel);
|
|
|
|
|
if(confirmed)
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/what-is-an-organization/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task TwoStepAsync()
|
|
|
|
|
{
|
|
|
|
|
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.TwoStepLoginConfirmation,
|
|
|
|
|
AppResources.TwoStepLogin, AppResources.Yes, AppResources.Cancel);
|
|
|
|
|
if(confirmed)
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/setup-two-step-login/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ChangePasswordAsync()
|
|
|
|
|
{
|
|
|
|
|
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.ChangePasswordConfirmation,
|
|
|
|
|
AppResources.ChangeMasterPassword, AppResources.Yes, AppResources.Cancel);
|
|
|
|
|
if(confirmed)
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.LaunchUri("https://help.bitwarden.com/article/change-your-master-password/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task LogOutAsync()
|
|
|
|
|
{
|
|
|
|
|
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.LogoutConfirmation,
|
|
|
|
|
AppResources.LogOut, AppResources.Yes, AppResources.Cancel);
|
|
|
|
|
if(confirmed)
|
|
|
|
|
{
|
|
|
|
|
_messagingService.Send("logout");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 21:47:50 +02:00
|
|
|
|
public async Task LockAsync()
|
|
|
|
|
{
|
|
|
|
|
await _lockService.LockAsync(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 20:55:18 +02:00
|
|
|
|
public async Task LockOptionsAsync()
|
|
|
|
|
{
|
|
|
|
|
var options = _lockOptions.Select(o => o.Key == _lockOptionValue ? $"✓ {o.Key}" : o.Key).ToArray();
|
|
|
|
|
var selection = await Page.DisplayActionSheet(AppResources.LockOptions, AppResources.Cancel, null, options);
|
|
|
|
|
if(selection == AppResources.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var cleanSelection = selection.Replace("✓ ", string.Empty);
|
|
|
|
|
var selectionOption = _lockOptions.FirstOrDefault(o => o.Key == cleanSelection);
|
|
|
|
|
_lockOptionValue = selectionOption.Key;
|
|
|
|
|
await _storageService.SaveAsync(Constants.LockOptionKey, selectionOption.Value);
|
|
|
|
|
BuildList();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 17:53:41 +02:00
|
|
|
|
private void BuildList()
|
|
|
|
|
{
|
|
|
|
|
var doUpper = Device.RuntimePlatform != Device.Android;
|
|
|
|
|
var manageItems = new List<SettingsPageListItem>
|
|
|
|
|
{
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.Folders },
|
2019-05-16 20:55:18 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.Sync, SubLabel = _lastSyncDate }
|
2019-05-14 17:53:41 +02:00
|
|
|
|
};
|
|
|
|
|
var securityItems = new List<SettingsPageListItem>
|
|
|
|
|
{
|
2019-05-16 20:55:18 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.LockOptions, SubLabel = _lockOptionValue },
|
2019-05-14 17:53:41 +02:00
|
|
|
|
new SettingsPageListItem { Name = string.Format(AppResources.UnlockWith, AppResources.Fingerprint) },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.UnlockWithPIN },
|
2019-05-15 19:35:17 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.LockNow },
|
2019-05-14 17:53:41 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.TwoStepLogin }
|
|
|
|
|
};
|
|
|
|
|
var accountItems = new List<SettingsPageListItem>
|
|
|
|
|
{
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.ChangeMasterPassword },
|
2019-05-15 18:54:48 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.FingerprintPhrase },
|
2019-05-14 17:53:41 +02:00
|
|
|
|
new SettingsPageListItem { Name = AppResources.LogOut }
|
|
|
|
|
};
|
2019-05-15 19:26:55 +02:00
|
|
|
|
var toolsItems = new List<SettingsPageListItem>
|
|
|
|
|
{
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.ImportItems },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.ExportVault },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.ShareVault },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.WebVault }
|
|
|
|
|
};
|
2019-05-14 17:53:41 +02:00
|
|
|
|
var otherItems = new List<SettingsPageListItem>
|
|
|
|
|
{
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.Options },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.About },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.HelpAndFeedback },
|
|
|
|
|
new SettingsPageListItem { Name = AppResources.RateTheApp }
|
|
|
|
|
};
|
2019-05-16 20:55:18 +02:00
|
|
|
|
GroupedItems.ResetWithRange(new List<SettingsPageListGroup>
|
2019-05-14 17:53:41 +02:00
|
|
|
|
{
|
|
|
|
|
new SettingsPageListGroup(manageItems, AppResources.Manage, doUpper),
|
|
|
|
|
new SettingsPageListGroup(securityItems, AppResources.Security, doUpper),
|
|
|
|
|
new SettingsPageListGroup(accountItems, AppResources.Account, doUpper),
|
2019-05-15 19:26:55 +02:00
|
|
|
|
new SettingsPageListGroup(toolsItems, AppResources.Tools, doUpper),
|
2019-05-14 17:53:41 +02:00
|
|
|
|
new SettingsPageListGroup(otherItems, AppResources.Other, doUpper)
|
2019-05-16 20:55:18 +02:00
|
|
|
|
});
|
2019-05-14 17:53:41 +02:00
|
|
|
|
}
|
2019-03-29 04:52:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|