Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add support for temp or global password settings persist (#167)

Leendert de Borstb0e939ef2356
diff --git a/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor b/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor
index e798ca3de..cc0c19d8b 100644
--- a/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor
+++ b/src/AliasVault.Client/Main/Components/Forms/EditPasswordFormRow.razor
@@ -35,7 +35,7 @@
@if (IsPasswordSettingsVisible)
{
- <PasswordSettingsPopup
+ <PasswordSettingsPopup
PasswordSettings="@PasswordSettings"
IsTemporary="true"
OnSaveSettings="@HandlePasswordSettingsSaved"
diff --git a/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
index 63f313abe..1099cbbdd 100644
--- a/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
+++ b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
@@ -44,8 +44,8 @@
private void HandlePasswordSettingsSaved(PasswordSettings settings)
{
- PasswordSettings = settings;
// The settings are already saved in the PasswordSettingsPopup component
// We just need to update our local state
+ PasswordSettings = settings;
}
}
diff --git a/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
index 2e0e18496..e0201215b 100644
--- a/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
+++ b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
@@ -1,4 +1,5 @@
@inject DbService DbService
+@inject GlobalLoadingService GlobalLoadingService
<div class="fixed inset-0 bg-gray-600 bg-opacity-50 z-30 overflow-y-auto h-full w-full" @onclick="OnClose">
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white dark:bg-gray-800" @onclick:stopPropagation>
@@ -49,12 +50,18 @@
</div>
</div>
- <div class="flex justify-between pt-4">
+ <div class="flex @(IsTemporary ? "justify-between" : "justify-end") pt-4">
<button type="button" class="px-4 py-2 bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-400 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600" @onclick="OnClose">
Cancel
</button>
- <button type="button" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OnSave">
- Save Settings
+ @if (IsTemporary)
+ {
+ <button type="button" class="px-4 py-2 bg-yellow-600 text-white rounded-md hover:bg-yellow-700 focus:outline-none focus:ring-2 focus:ring-yellow-500 dark:bg-yellow-700 dark:hover:bg-yellow-600" @onclick="OnSaveTemporary">
+ Use Just Once
+ </button>
+ }
+ <button type="button" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OnSaveGlobal">
+ Save Globally
</button>
</div>
</div>
@@ -70,13 +77,14 @@
public PasswordSettings PasswordSettings { get; set; } = new();
/// <summary>
- /// Whether change is temporary.
+ /// Whether temporary change is allowed. If true, component will show both global and temporary options.
+ /// If false, only global settings are available.
/// </summary>
[Parameter]
public bool IsTemporary { get; set; }
/// <summary>
- /// Callback invoked when settings have been changed.
+ /// Callback invoked when settings have been changed, with a boolean indicating if it's a global save.
/// </summary>
[Parameter]
public EventCallback<PasswordSettings> OnSaveSettings { get; set; }
@@ -100,13 +108,27 @@
_previewPassword = CredentialService.GenerateRandomPassword(PasswordSettings);
}
- private async Task OnSave()
+ /// <summary>
+ /// Persist changed password settings globally in vault.
+ /// </summary>
+ private async Task OnSaveGlobal()
+ {
+ // Save globally to DB
+ GlobalLoadingService.Show();
+ var settingsJson = System.Text.Json.JsonSerializer.Serialize(PasswordSettings);
+ await DbService.Settings.SetSettingAsync("PasswordGenerationSettings", settingsJson);
+ GlobalLoadingService.Hide();
+
+ // Notify parent with IsGlobal=true
+ await OnSaveSettings.InvokeAsync(PasswordSettings);
+ await OnClose.InvokeAsync();
+ }
+
+ /// <summary>
+ /// Do not persist changes in vault but just return the new settings to the parent component.
+ /// </summary>
+ private async Task OnSaveTemporary()
{
- if (!IsTemporary)
- {
- var settingsJson = System.Text.Json.JsonSerializer.Serialize(PasswordSettings);
- await DbService.Settings.SetSettingAsync("PasswordGenerationSettings", settingsJson);
- }
await OnSaveSettings.InvokeAsync(PasswordSettings);
await OnClose.InvokeAsync();
}