mirror of
https://github.com/bitwarden/mobile
synced 2026-01-06 02:23:57 +00:00
stub out password generator page functionality
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage
|
||||
<pages:BaseContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Bit.App.Pages.GeneratorPage"
|
||||
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||
xmlns:controls="clr-namespace:Bit.App.Controls"
|
||||
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||
x:DataType="pages:GeneratorPageViewModel"
|
||||
Title="{Binding PageTitle}">
|
||||
@@ -11,27 +12,45 @@
|
||||
<pages:GeneratorPageViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<StackLayout>
|
||||
<!-- Place new controls here -->
|
||||
<Label
|
||||
Text="Generator!"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="CenterAndExpand" />
|
||||
<Label
|
||||
Text="{u:I18n AttachmentLargeWarning, P1='10 MB'}"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="CenterAndExpand" />
|
||||
<Label
|
||||
Text=""
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="CenterAndExpand">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Text="{u:I18n Select}"
|
||||
Clicked="Select_Clicked"
|
||||
Order="Primary"
|
||||
x:Name="_selectItem" />
|
||||
<ToolbarItem Text="{u:I18n PasswordHistory}"
|
||||
Clicked="History_Clicked"
|
||||
Order="Secondary" />
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<Label.FontFamily>
|
||||
<OnPlatform x:TypeArguments="x:String"
|
||||
Android="FontAwesome.ttf#FontAwesome"
|
||||
iOS="FontAwesome" />
|
||||
</Label.FontFamily>
|
||||
</Label>
|
||||
<StackLayout Spacing="20">
|
||||
<StackLayout StyleClass="box">
|
||||
<controls:MonoLabel
|
||||
Text="{Binding Password}"
|
||||
Margin="0, 20"
|
||||
StyleClass="text-lg"
|
||||
HorizontalOptions="Center" />
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<Button Text="{u:I18n RegeneratePassword}"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Clicked="Regenerate_Clicked"></Button>
|
||||
<Button Text="{u:I18n CopyPassword}"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Clicked="Copy_Clicked"></Button>
|
||||
</StackLayout>
|
||||
<StackLayout StyleClass="box-row-header">
|
||||
<Label Text="{u:I18n Options}"
|
||||
StyleClass="box-header, box-header-platform" />
|
||||
</StackLayout>
|
||||
<StackLayout StyleClass="box-row, box-row-input">
|
||||
<Label
|
||||
Text="{u:I18n Type}"
|
||||
StyleClass="box-label" />
|
||||
<Picker
|
||||
ItemsSource="{Binding TypeOptions, Mode=OneTime}"
|
||||
SelectedIndex="{Binding TypeSelectedIndex}"
|
||||
StyleClass="box-value" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
|
||||
</ContentPage>
|
||||
</pages:BaseContentPage>
|
||||
|
||||
@@ -1,18 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
public partial class GeneratorPage : ContentPage
|
||||
public partial class GeneratorPage : BaseContentPage
|
||||
{
|
||||
private GeneratorPageViewModel _vm;
|
||||
|
||||
public GeneratorPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
_vm = BindingContext as GeneratorPageViewModel;
|
||||
_vm.Page = this;
|
||||
}
|
||||
|
||||
protected async override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
await _vm.InitAsync();
|
||||
}
|
||||
|
||||
private async void Regenerate_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await _vm.RegenerateAsync();
|
||||
}
|
||||
|
||||
private async void Copy_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await _vm.CopyAsync();
|
||||
}
|
||||
|
||||
private void Select_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void History_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
src/App/Resources/AppResources.Designer.cs
generated
27
src/App/Resources/AppResources.Designer.cs
generated
@@ -2589,6 +2589,15 @@ namespace Bit.App.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Number of Words.
|
||||
/// </summary>
|
||||
public static string NumberOfWords {
|
||||
get {
|
||||
return ResourceManager.GetString("NumberOfWords", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to October.
|
||||
/// </summary>
|
||||
@@ -2661,6 +2670,15 @@ namespace Bit.App.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Passphrase.
|
||||
/// </summary>
|
||||
public static string Passphrase {
|
||||
get {
|
||||
return ResourceManager.GetString("Passphrase", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Passport Number.
|
||||
/// </summary>
|
||||
@@ -3741,6 +3759,15 @@ namespace Bit.App.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Word Separator.
|
||||
/// </summary>
|
||||
public static string WordSeparator {
|
||||
get {
|
||||
return ResourceManager.GetString("WordSeparator", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Yes.
|
||||
/// </summary>
|
||||
|
||||
@@ -1447,4 +1447,13 @@
|
||||
<data name="ShareDesc" xml:space="preserve">
|
||||
<value>Choose an organization that you wish to share this item with. Sharing transfers ownership of the item to the organization. You will no longer be the direct owner of this item once it has been shared.</value>
|
||||
</data>
|
||||
<data name="NumberOfWords" xml:space="preserve">
|
||||
<value>Number of Words</value>
|
||||
</data>
|
||||
<data name="Passphrase" xml:space="preserve">
|
||||
<value>Passphrase</value>
|
||||
</data>
|
||||
<data name="WordSeparator" xml:space="preserve">
|
||||
<value>Word Separator</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -40,7 +40,8 @@
|
||||
Value="Small" />
|
||||
</Style>
|
||||
<Style TargetType="Label"
|
||||
Class="text-lg">
|
||||
Class="text-lg"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="FontSize"
|
||||
Value="Large" />
|
||||
</Style>
|
||||
|
||||
Reference in New Issue
Block a user