mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-20 15:41:40 -04:00
Cleanup (#167)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
}
|
||||
</svg>
|
||||
</button>
|
||||
<button type="button" class="px-3 text-gray-500 dark:text-white bg-gray-200 hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium text-sm border-l border-gray-300 dark:border-gray-700 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" @onclick="TogglePasswordSettings">
|
||||
<button type="button" class="px-3 text-gray-500 dark:text-white bg-gray-200 hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium text-sm border-l border-gray-300 dark:border-gray-700 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" @onclick="ShowPasswordSettings">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
|
||||
@@ -36,7 +36,7 @@
|
||||
@if (IsPasswordSettingsVisible)
|
||||
{
|
||||
<PasswordSettingsPopup
|
||||
PasswordSettings="@PasswordSettings"
|
||||
PasswordSettings="@_internalPasswordSettings"
|
||||
IsTemporary="true"
|
||||
OnSaveSettings="@HandlePasswordSettingsSaved"
|
||||
OnClose="@ClosePasswordSettings" />
|
||||
@@ -79,17 +79,32 @@
|
||||
[Parameter]
|
||||
public bool ShowPassword { get; set; } = false;
|
||||
|
||||
private PasswordSettings PasswordSettings { get; set; } = new();
|
||||
/// <summary>
|
||||
/// Whether the password settings popup is visible.
|
||||
/// </summary>
|
||||
private bool IsPasswordSettingsVisible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the password is visible in plain text or not.
|
||||
/// </summary>
|
||||
private bool _internalShowPassword;
|
||||
|
||||
/// <summary>
|
||||
/// Internal copy of the password settings which can be mutated without affecting the global settings.
|
||||
/// </summary>
|
||||
private PasswordSettings _internalPasswordSettings = new();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the component has been initialized.
|
||||
/// </summary>
|
||||
private bool _hasInitialized;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
PasswordSettings = DbService.Settings.PasswordSettings;
|
||||
_internalShowPassword = ShowPassword;
|
||||
_internalPasswordSettings = DbService.Settings.PasswordSettings;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -104,45 +119,62 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the password plain text visibility.
|
||||
/// </summary>
|
||||
private void TogglePasswordVisibility()
|
||||
{
|
||||
_internalShowPassword = !_internalShowPassword;
|
||||
}
|
||||
|
||||
private void TogglePasswordSettings()
|
||||
/// <summary>
|
||||
/// Shows the password settings popup.
|
||||
/// </summary>
|
||||
private void ShowPasswordSettings()
|
||||
{
|
||||
IsPasswordSettingsVisible = !IsPasswordSettingsVisible;
|
||||
IsPasswordSettingsVisible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the password settings popup.
|
||||
/// </summary>
|
||||
private void ClosePasswordSettings()
|
||||
{
|
||||
IsPasswordSettingsVisible = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the local value when the input field changes.
|
||||
/// </summary>
|
||||
private async Task OnInputChanged(ChangeEventArgs e)
|
||||
{
|
||||
Value = e.Value?.ToString() ?? string.Empty;
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates current password when password settings have been changed.
|
||||
/// </summary>
|
||||
private async Task HandlePasswordSettingsSaved((PasswordSettings settings, string generatedPassword) args)
|
||||
{
|
||||
PasswordSettings = args.settings;
|
||||
_internalPasswordSettings = args.settings;
|
||||
_internalShowPassword = true;
|
||||
Value = args.generatedPassword;
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new password.
|
||||
/// </summary>
|
||||
private async Task GeneratePassword()
|
||||
{
|
||||
// Generate the password
|
||||
string password = CredentialService.GenerateRandomPassword(PasswordSettings);
|
||||
string newPassword = CredentialService.GenerateRandomPassword(_internalPasswordSettings);
|
||||
|
||||
// Update the value
|
||||
Value = password;
|
||||
// Update the local value.
|
||||
Value = newPassword;
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
|
||||
// Make password visible when it's (re)generated
|
||||
// Make password visible when it's (re)generated.
|
||||
_internalShowPassword = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,25 @@
|
||||
PasswordSettings = DbService.Settings.PasswordSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the password settings popup.
|
||||
/// </summary>
|
||||
private void OpenSettings()
|
||||
{
|
||||
IsSettingsVisible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the password settings popup.
|
||||
/// </summary>
|
||||
private void CloseSettings()
|
||||
{
|
||||
IsSettingsVisible = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the password settings saved event.
|
||||
/// </summary>
|
||||
private void HandlePasswordSettingsSaved((PasswordSettings settings, string generatedPassword) args)
|
||||
{
|
||||
// The settings are already saved in the PasswordSettingsPopup component
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
/// The PasswordSettings to use.
|
||||
/// The PasswordSettings to mutate.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public PasswordSettings PasswordSettings { get; set; } = new();
|
||||
@@ -104,7 +104,14 @@
|
||||
[Parameter]
|
||||
public EventCallback OnClose { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Local copy of password settings that are currently being edited.
|
||||
/// </summary>
|
||||
private PasswordSettings _workingSettings = new();
|
||||
|
||||
/// <summary>
|
||||
/// The preview password.
|
||||
/// </summary>
|
||||
private string _previewPassword = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -124,6 +131,9 @@
|
||||
RefreshPreview();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refresh the preview password.
|
||||
/// </summary>
|
||||
private void RefreshPreview()
|
||||
{
|
||||
try {
|
||||
@@ -183,7 +193,7 @@
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle Enter key press - submits the form based on context.
|
||||
/// Handle Enter key press, submits the form based on context.
|
||||
/// </summary>
|
||||
private async Task HandleEnterKey()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user