1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-17 00:33:20 +00:00

stub out password generator page functionality

This commit is contained in:
Kyle Spearrin
2019-05-13 12:13:23 -04:00
parent 29b37219c2
commit 28473dd85f
10 changed files with 280 additions and 34 deletions

View File

@@ -1,14 +1,100 @@
using System;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Models.Domain;
using Bit.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Bit.App.Pages
{
public class GeneratorPageViewModel : BaseViewModel
{
private readonly IPasswordGenerationService _passwordGenerationService;
private readonly IPlatformUtilsService _platformUtilsService;
private PasswordGenerationOptions _options;
private string _password;
private bool _isPassword;
private int _typeSelectedIndex;
public GeneratorPageViewModel()
{
PageTitle = "Password Generator";
_passwordGenerationService = ServiceContainer.Resolve<IPasswordGenerationService>(
"passwordGenerationService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
PageTitle = AppResources.PasswordGenerator;
TypeOptions = new List<string> { AppResources.Password, AppResources.Passphrase };
}
public List<string> TypeOptions { get; set; }
public string Password
{
get => _password;
set => SetProperty(ref _password, value);
}
public bool IsPassword
{
get => _isPassword;
set => SetProperty(ref _isPassword, value);
}
public PasswordGenerationOptions Options
{
get => _options;
set => SetProperty(ref _options, value);
}
public int TypeSelectedIndex
{
get => _typeSelectedIndex;
set
{
if(SetProperty(ref _typeSelectedIndex, value))
{
TypeChanged();
}
}
}
public async Task InitAsync()
{
Options = await _passwordGenerationService.GetOptionsAsync();
TypeSelectedIndex = Options.Type == "passphrase" ? 1 : 0;
Password = await _passwordGenerationService.GeneratePasswordAsync(Options);
await _passwordGenerationService.AddHistoryAsync(Password);
}
public async Task RegenerateAsync()
{
Password = await _passwordGenerationService.GeneratePasswordAsync(Options);
await _passwordGenerationService.AddHistoryAsync(Password);
}
public async Task SaveOptionsAsync(bool regenerate = true)
{
_passwordGenerationService.NormalizeOptions(Options);
await _passwordGenerationService.SaveOptionsAsync(Options);
if(regenerate)
{
await RegenerateAsync();
}
}
public async Task CopyAsync()
{
await _platformUtilsService.CopyToClipboardAsync(Password);
_platformUtilsService.ShowToast("success", null, AppResources.CopiedPassword);
}
public async void TypeChanged()
{
IsPassword = TypeSelectedIndex == 0;
Options.Type = IsPassword ? "password" : "passphrase";
await SaveOptionsAsync();
}
}
}