diff --git a/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor b/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor index 45e573976..e798ca3de 100644 --- a/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor +++ b/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor @@ -35,53 +35,11 @@ @if (IsPasswordSettingsVisible) { -
-
-
-

Password Generation Settings

-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
-
-
-
-
+ } @code { @@ -146,16 +104,6 @@ } } - private async Task SavePasswordSettings() - { - var settingsJson = System.Text.Json.JsonSerializer.Serialize(PasswordSettings); - await DbService.Settings.SetSettingAsync("PasswordGenerationSettings", settingsJson); - ClosePasswordSettings(); - - // Generate a new password with the new settings - await GeneratePassword(); - } - private void TogglePasswordVisibility() { _internalShowPassword = !_internalShowPassword; @@ -177,6 +125,12 @@ await ValueChanged.InvokeAsync(Value); } + private async Task HandlePasswordSettingsSaved(PasswordSettings settings) + { + PasswordSettings = settings; + await GeneratePassword(); + } + private async Task GeneratePassword() { // Generate the password diff --git a/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor new file mode 100644 index 000000000..63f313abe --- /dev/null +++ b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor @@ -0,0 +1,51 @@ +@inject DbService DbService + +
+
+

Default Password Generation Settings

+ +
+
+ Configure the default settings used when generating new passwords. These settings will be used unless overridden for specific entries. +
+
+ +@if (IsSettingsVisible) +{ + +} + +@code { + private PasswordSettings PasswordSettings { get; set; } = new(); + private bool IsSettingsVisible { get; set; } + + /// + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + PasswordSettings = DbService.Settings.PasswordSettings; + } + + private void OpenSettings() + { + IsSettingsVisible = true; + } + + private void CloseSettings() + { + IsSettingsVisible = false; + } + + private void HandlePasswordSettingsSaved(PasswordSettings settings) + { + PasswordSettings = settings; + // The settings are already saved in the PasswordSettingsPopup component + // We just need to update our local state + } +} diff --git a/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor new file mode 100644 index 000000000..2e0e18496 --- /dev/null +++ b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor @@ -0,0 +1,113 @@ +@inject DbService DbService + +
+
+
+

Password Generation Settings

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+
+ +
+ + +
+
+
+
+
+ +@code { + /// + /// The PasswordSettings to use. + /// + [Parameter] + public PasswordSettings PasswordSettings { get; set; } = new(); + + /// + /// Whether change is temporary. + /// + [Parameter] + public bool IsTemporary { get; set; } + + /// + /// Callback invoked when settings have been changed. + /// + [Parameter] + public EventCallback OnSaveSettings { get; set; } + + /// + /// Callback invoked when popup is closed. + /// + [Parameter] + public EventCallback OnClose { get; set; } + + private string _previewPassword = string.Empty; + + /// + protected override void OnInitialized() + { + RefreshPreview(); + } + + private void RefreshPreview() + { + _previewPassword = CredentialService.GenerateRandomPassword(PasswordSettings); + } + + private async Task OnSave() + { + if (!IsTemporary) + { + var settingsJson = System.Text.Json.JsonSerializer.Serialize(PasswordSettings); + await DbService.Settings.SetSettingAsync("PasswordGenerationSettings", settingsJson); + } + await OnSaveSettings.InvokeAsync(PasswordSettings); + await OnClose.InvokeAsync(); + } +} diff --git a/src/AliasVault.Client/Properties/launchSettings.json b/src/AliasVault.Client/Properties/launchSettings.json index d910de557..ab1c637bd 100644 --- a/src/AliasVault.Client/Properties/launchSettings.json +++ b/src/AliasVault.Client/Properties/launchSettings.json @@ -16,7 +16,8 @@ "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "http://localhost:5067", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "DOTNET_MODIFIABLE_ASSEMBLIES": "debug", + "ASPNETCORE_ENVIRONMENT": "Development", } }, "http-release": { diff --git a/src/AliasVault.Client/_Imports.razor b/src/AliasVault.Client/_Imports.razor index 12334b443..292c9e042 100644 --- a/src/AliasVault.Client/_Imports.razor +++ b/src/AliasVault.Client/_Imports.razor @@ -19,6 +19,7 @@ @using AliasVault.Client.Main.Components.Forms @using AliasVault.Client.Main.Components.Layout @using AliasVault.Client.Main.Components.Loading +@using AliasVault.Client.Main.Components.Settings @using AliasVault.Client.Main.Components.TotpCodes @using AliasVault.Client.Main.Components.Widgets @using AliasVault.Client.Main.Models