mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-27 12:26:31 +01:00
[SG-666][SG-667] Email is not prefilled and username isn't generated automatically (#2109)
* SG-666 SG-667 - Email is now prefilled for plus addressed email username type * Username is auto generated upon navigation * SG-666 - Fixed PR comments * Added missing property initialization
This commit is contained in:
parent
90e0b5dcf0
commit
a890ee6612
@ -20,6 +20,7 @@ namespace Bit.App.Pages
|
|||||||
private readonly IPlatformUtilsService _platformUtilsService;
|
private readonly IPlatformUtilsService _platformUtilsService;
|
||||||
private readonly IClipboardService _clipboardService;
|
private readonly IClipboardService _clipboardService;
|
||||||
private readonly IUsernameGenerationService _usernameGenerationService;
|
private readonly IUsernameGenerationService _usernameGenerationService;
|
||||||
|
private readonly ITokenService _tokenService;
|
||||||
readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>("logger");
|
readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>("logger");
|
||||||
|
|
||||||
private PasswordGenerationOptions _options;
|
private PasswordGenerationOptions _options;
|
||||||
@ -49,8 +50,6 @@ namespace Bit.App.Pages
|
|||||||
private bool _showFirefoxRelayApiAccessToken;
|
private bool _showFirefoxRelayApiAccessToken;
|
||||||
private bool _showAnonAddyApiAccessToken;
|
private bool _showAnonAddyApiAccessToken;
|
||||||
private bool _showSimpleLoginApiKey;
|
private bool _showSimpleLoginApiKey;
|
||||||
private UsernameEmailType _catchAllEmailTypeSelected;
|
|
||||||
private UsernameEmailType _plusAddressedEmailTypeSelected;
|
|
||||||
private bool _editMode;
|
private bool _editMode;
|
||||||
|
|
||||||
public GeneratorPageViewModel()
|
public GeneratorPageViewModel()
|
||||||
@ -59,6 +58,7 @@ namespace Bit.App.Pages
|
|||||||
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>();
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>();
|
||||||
_clipboardService = ServiceContainer.Resolve<IClipboardService>();
|
_clipboardService = ServiceContainer.Resolve<IClipboardService>();
|
||||||
_usernameGenerationService = ServiceContainer.Resolve<IUsernameGenerationService>();
|
_usernameGenerationService = ServiceContainer.Resolve<IUsernameGenerationService>();
|
||||||
|
_tokenService = ServiceContainer.Resolve<ITokenService>();
|
||||||
|
|
||||||
PageTitle = AppResources.Generator;
|
PageTitle = AppResources.Generator;
|
||||||
GeneratorTypeOptions = new List<GeneratorType> {
|
GeneratorTypeOptions = new List<GeneratorType> {
|
||||||
@ -157,7 +157,7 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
public bool ShowUsernameEmailType
|
public bool ShowUsernameEmailType
|
||||||
{
|
{
|
||||||
get => !string.IsNullOrWhiteSpace(EmailWebsite) || EditMode;
|
get => !string.IsNullOrWhiteSpace(EmailWebsite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Length
|
public int Length
|
||||||
@ -367,7 +367,7 @@ namespace Bit.App.Pages
|
|||||||
IsUsername = value == GeneratorType.Username;
|
IsUsername = value == GeneratorType.Username;
|
||||||
TriggerPropertyChanged(nameof(GeneratorTypeSelected));
|
TriggerPropertyChanged(nameof(GeneratorTypeSelected));
|
||||||
SaveOptionsAsync().FireAndForget();
|
SaveOptionsAsync().FireAndForget();
|
||||||
SaveUsernameOptionsAsync(false).FireAndForget();
|
SaveUsernameOptionsAsync().FireAndForget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,6 +382,7 @@ namespace Bit.App.Pages
|
|||||||
IsPassword = value == 0;
|
IsPassword = value == 0;
|
||||||
TriggerPropertyChanged(nameof(PasswordTypeSelectedIndex));
|
TriggerPropertyChanged(nameof(PasswordTypeSelectedIndex));
|
||||||
SaveOptionsAsync().FireAndForget();
|
SaveOptionsAsync().FireAndForget();
|
||||||
|
SaveUsernameOptionsAsync().FireAndForget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,7 +397,7 @@ namespace Bit.App.Pages
|
|||||||
_usernameOptions.Type = value;
|
_usernameOptions.Type = value;
|
||||||
Username = Constants.DefaultUsernameGenerated;
|
Username = Constants.DefaultUsernameGenerated;
|
||||||
TriggerPropertyChanged(nameof(UsernameTypeSelected), new string[] { nameof(UsernameTypeDescriptionLabel) });
|
TriggerPropertyChanged(nameof(UsernameTypeSelected), new string[] { nameof(UsernameTypeDescriptionLabel) });
|
||||||
SaveUsernameOptionsAsync(false).FireAndForget();
|
SaveUsernameOptionsAsync().FireAndForget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,26 +565,28 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
public UsernameEmailType PlusAddressedEmailTypeSelected
|
public UsernameEmailType PlusAddressedEmailTypeSelected
|
||||||
{
|
{
|
||||||
get => _plusAddressedEmailTypeSelected;
|
get => _usernameOptions.PlusAddressedEmailType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _plusAddressedEmailTypeSelected, value))
|
if (_usernameOptions.PlusAddressedEmailType != value)
|
||||||
{
|
{
|
||||||
_usernameOptions.PlusAddressedEmailType = value;
|
_usernameOptions.PlusAddressedEmailType = value;
|
||||||
SaveUsernameOptionsAsync(false).FireAndForget();
|
TriggerPropertyChanged(nameof(PlusAddressedEmailTypeSelected));
|
||||||
|
SaveUsernameOptionsAsync().FireAndForget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UsernameEmailType CatchAllEmailTypeSelected
|
public UsernameEmailType CatchAllEmailTypeSelected
|
||||||
{
|
{
|
||||||
get => _catchAllEmailTypeSelected;
|
get => _usernameOptions.CatchAllEmailType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _catchAllEmailTypeSelected, value))
|
if (_usernameOptions.CatchAllEmailType != value)
|
||||||
{
|
{
|
||||||
_usernameOptions.CatchAllEmailType = value;
|
_usernameOptions.CatchAllEmailType = value;
|
||||||
SaveUsernameOptionsAsync(false).FireAndForget();
|
TriggerPropertyChanged(nameof(CatchAllEmailTypeSelected));
|
||||||
|
SaveUsernameOptionsAsync().FireAndForget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -601,16 +604,28 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
(_options, EnforcedPolicyOptions) = await _passwordGenerationService.GetOptionsAsync();
|
(_options, EnforcedPolicyOptions) = await _passwordGenerationService.GetOptionsAsync();
|
||||||
LoadFromOptions();
|
LoadFromOptions();
|
||||||
await RegenerateAsync();
|
|
||||||
|
|
||||||
_usernameOptions = await _usernameGenerationService.GetOptionsAsync();
|
_usernameOptions = await _usernameGenerationService.GetOptionsAsync();
|
||||||
|
_usernameOptions.PlusAddressedEmail = _tokenService.GetEmail();
|
||||||
|
_usernameOptions.EmailWebsite = EmailWebsite;
|
||||||
|
_usernameOptions.CatchAllEmailType = _usernameOptions.PlusAddressedEmailType = string.IsNullOrWhiteSpace(EmailWebsite) || !EditMode ? UsernameEmailType.Random : UsernameEmailType.Website;
|
||||||
|
|
||||||
if (!EditMode)
|
if (!IsUsername)
|
||||||
{
|
{
|
||||||
_usernameOptions.CatchAllEmailType = _usernameOptions.PlusAddressedEmailType = UsernameEmailType.Random;
|
await RegenerateAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (UsernameTypeSelected != UsernameType.ForwardedEmailAlias)
|
||||||
|
{
|
||||||
|
await RegenerateUsernameAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Username = Constants.DefaultUsernameGenerated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TriggerUsernamePropertiesChanged();
|
TriggerUsernamePropertiesChanged();
|
||||||
Username = Constants.DefaultUsernameGenerated;
|
|
||||||
|
|
||||||
_doneIniting = true;
|
_doneIniting = true;
|
||||||
}
|
}
|
||||||
@ -668,10 +683,14 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
await _usernameGenerationService.SaveOptionsAsync(_usernameOptions);
|
await _usernameGenerationService.SaveOptionsAsync(_usernameOptions);
|
||||||
|
|
||||||
if (regenerate)
|
if (regenerate && UsernameTypeSelected != UsernameType.ForwardedEmailAlias)
|
||||||
{
|
{
|
||||||
await RegenerateUsernameAsync();
|
await RegenerateUsernameAsync();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Username = Constants.DefaultUsernameGenerated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SliderChangedAsync()
|
public async Task SliderChangedAsync()
|
||||||
|
@ -605,6 +605,8 @@ namespace Bit.App.Pages
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var website = Cipher?.Login?.Uris?.FirstOrDefault()?.Host;
|
||||||
|
|
||||||
var page = new GeneratorPage(false, async (username) =>
|
var page = new GeneratorPage(false, async (username) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -617,7 +619,7 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
OnGenerateUsernameException(ex);
|
OnGenerateUsernameException(ex);
|
||||||
}
|
}
|
||||||
}, isUsernameGenerator: true, emailWebsite: Cipher?.Name, editMode: true);
|
}, isUsernameGenerator: true, emailWebsite: website, editMode: true);
|
||||||
await Page.Navigation.PushModalAsync(new NavigationPage(page));
|
await Page.Navigation.PushModalAsync(new NavigationPage(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user