Skip to content

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

Add username generate button, fix form validation bugs, tweak UI (#144)

Leendert de Borstb8cb3c4d7862
diff --git a/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor b/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor
index 1838de04f..7e227c231 100644
--- a/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor
+++ b/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor
@@ -91,7 +91,7 @@
/// The email address to show recent emails for.
/// </summary>
[Parameter]
- public string EmailAddress { get; set; } = string.Empty;
+ public string? EmailAddress { get; set; } = string.Empty;
private List<MailboxEmailApiModel> MailboxEmails { get; set; } = new();
private bool ShowComponent { get; set; } = false;
@@ -111,6 +111,11 @@
{
await base.OnInitializedAsync();
+ if (EmailAddress is null)
+ {
+ return;
+ }
+
// Check if email has a known SpamOK domain, if not, don't show this component.
if (IsSpamOkDomain(EmailAddress) || IsAliasVaultDomain(EmailAddress))
{
@@ -131,6 +136,12 @@
protected override void OnParametersSet()
{
base.OnParametersSet();
+
+ if (EmailAddress is null)
+ {
+ return;
+ }
+
IsSpamOk = IsSpamOkDomain(EmailAddress);
}
@@ -192,7 +203,7 @@
private async Task LoadRecentEmailsAsync()
{
- if (!ShowComponent)
+ if (!ShowComponent || EmailAddress is null)
{
return;
}
@@ -218,6 +229,11 @@
/// </summary>
private async Task OpenEmail(int emailId)
{
+ if (EmailAddress is null)
+ {
+ return;
+ }
+
// Get email prefix, which is the part before the @ symbol.
string emailPrefix = EmailAddress.Split('@')[0];
diff --git a/src/AliasVault.Client/Main/Components/Forms/EditEmailFormRow.razor b/src/AliasVault.Client/Main/Components/Forms/EditEmailFormRow.razor
index f64af69c2..1cd48ec9e 100644
--- a/src/AliasVault.Client/Main/Components/Forms/EditEmailFormRow.razor
+++ b/src/AliasVault.Client/Main/Components/Forms/EditEmailFormRow.razor
@@ -82,7 +82,7 @@
/// The value of the input field. This should be the full email address.
/// </summary>
[Parameter]
- public string Value { get; set; } = string.Empty;
+ public string? Value { get; set; } = string.Empty;
/// <summary>
/// Callback that is triggered when the value changes.
@@ -113,6 +113,11 @@
{
base.OnParametersSet();
+ if (Value is null)
+ {
+ return;
+ }
+
if (Value.Contains('@'))
{
SelectedDomain = Value.Split('@')[1];
@@ -176,6 +181,11 @@
private void ToggleCustomDomain()
{
+ if (Value is null)
+ {
+ return;
+ }
+
IsCustomDomain = !IsCustomDomain;
if (!IsCustomDomain && !Value.Contains('@'))
{
diff --git a/src/AliasVault.Client/Main/Models/BreadcrumbItem.cs b/src/AliasVault.Client/Main/Models/BreadcrumbItem.cs
index bc68cf068..6d2c55f1b 100644
--- a/src/AliasVault.Client/Main/Models/BreadcrumbItem.cs
+++ b/src/AliasVault.Client/Main/Models/BreadcrumbItem.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Client.Main.Models;
/// <summary>
/// Represents a breadcrumb item for the breadcrumb component.
/// </summary>
-public class BreadcrumbItem
+public sealed class BreadcrumbItem
{
/// <summary>
/// Gets or sets the display name for the breadcrumb item.
diff --git a/src/AliasVault.Client/Main/Models/CredentialEdit.cs b/src/AliasVault.Client/Main/Models/CredentialEdit.cs
index ddf99afcb..50163c8dd 100644
--- a/src/AliasVault.Client/Main/Models/CredentialEdit.cs
+++ b/src/AliasVault.Client/Main/Models/CredentialEdit.cs
@@ -9,6 +9,7 @@ namespace AliasVault.Client.Main.Models;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using AliasClientDb;
using AliasVault.Client.Main.Models.FormValidation;
@@ -16,7 +17,7 @@ using AliasVault.Client.Main.Models.FormValidation;
/// <summary>
/// Credential edit model.
/// </summary>
-public class CredentialEdit
+public sealed class CredentialEdit
{
/// <summary>
/// Gets or sets the Id of the login.
@@ -37,6 +38,7 @@ public class CredentialEdit
/// Gets or sets the name of the service.
/// </summary>
[Required]
+ [Display(Name = "Service Name")]
public string ServiceName { get; set; } = null!;
/// <summary>
diff --git a/src/AliasVault.Client/Main/Models/CredentialListEntry.cs b/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
index 40f7ec0d6..5827fd7c4 100644
--- a/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
+++ b/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Client.Main.Models;
/// <summary>
/// Alias list entry model. This model is used to represent an alias in a list with simplified properties.
/// </summary>
-public class CredentialListEntry
+public sealed class CredentialListEntry
{
/// <summary>
/// Gets or sets the alias id.
diff --git a/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs b/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
index e8611b92a..c087ab515 100644
--- a/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
+++ b/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
@@ -17,7 +17,7 @@ using System.Globalization;
/// Initializes a new instance of the <see cref="StringDateFormatAttribute"/> class.
/// </remarks>
/// <param name="format">The date format to validate.</param>
-public class StringDateFormatAttribute(string format) : ValidationAttribute
+public sealed class StringDateFormatAttribute(string format) : ValidationAttribute
{
/// <summary>
/// Check if the date string is in the correct format.
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
index 09e84a500..b00c32353 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
@@ -3,6 +3,11 @@
@inherits MainBase
@inject CredentialService CredentialService
@using System.Globalization
+@using System.Text.Json
+@using System.Text.Json.Serialization
+@using AliasGenerators.Identity
+@using AliasGenerators.Identity.Implementations
+@using AliasGenerators.Identity.Models
@if (EditMode)
{
@@ -23,6 +28,10 @@ else {
else {
<h1 class="text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">Add credentials</h1>
}
+ <div>
+ <button type="button" @onclick="TriggerFormSubmit" class="px-4 py-2 text-white bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-300 dark:bg-green-500 dark:hover:bg-green-600 dark:focus:ring-green-800">Save Credentials</button>
+ <button type="button" @onclick="Cancel" class="px-4 py-2 text-white bg-red-600 rounded-lg hover:bg-red-700 focus:ring-4 focus:ring-red-300 dark:bg-red-500 dark:hover:bg-red-600 dark:focus:ring-red-800">Cancel</button>
+ </div>
</div>
@if (EditMode)
{
@@ -40,7 +49,7 @@ else {
}
else
{
- <EditForm Model="Obj" OnValidSubmit="SaveAlias">
+ <EditForm @ref="EditFormRef" Model="Obj" OnValidSubmit="SaveAlias">
<DataAnnotationsValidator />
<div class="grid grid-cols-3 px-4 pt-6 lg:gap-4 dark:bg-gray-900">
<div class="col-1">
@@ -85,20 +94,22 @@ else
<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<h3 class="mb-4 text-xl font-semibold dark:text-white">Login credentials</h3>
<div class="mb-4">
- <button type="button" class="px-4 py-2 text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 focus:ring-blue-300 dark:bg-blue-500 dark:hover:bg-blue-600 dark:focus:ring-blue-800" @onclick="GenerateRandomIdentity">Generate Random Identity</button>
- <button type="submit" class="px-4 py-2 text-white bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-300 dark:bg-green-500 dark:hover:bg-green-600 dark:focus:ring-green-800">Save Credentials</button>
+ <button type="button" @onclick="GenerateRandomAlias" class="px-4 py-2 text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-primary-300 dark:bg-primary-500 dark:hover:bg-primary-600 dark:focus:ring-primary-800">Generate Random Alias</button>
</div>
<div class="grid gap-6">
<div class="col-span-6 sm:col-span-3">
<EditEmailFormRow Id="email" Label="Email" @bind-Value="Obj.Alias.Email"></EditEmailFormRow>
</div>
<div class="col-span-6 sm:col-span-3">
- <EditFormRow Id="username" Label="Username" @bind-Value="Obj.Username"></EditFormRow>
+ <div class="relative">
+ <EditFormRow Id="username" Label="Username" @bind-Value="Obj.Username"></EditFormRow>
+ <button type="button" class="text-white absolute end-1 bottom-1 bg-gray-700 hover:bg-gray-800 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" @onclick="GenerateRandomUsername">New Username</button>
+ </div>
</div>
<div class="col-span-6 sm:col-span-3">
<div class="relative">
<EditFormRow Id="password" Label="Password" @bind-Value="Obj.Password.Value"></EditFormRow>
- <button type="button" class="text-white absolute end-1 bottom-1 bg-gray-700 hover:bg-gray-800 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" @onclick="GenerateRandomPassword">(Re)generate Random Password</button>
+ <button type="button" class="text-white absolute end-1 bottom-1 bg-gray-700 hover:bg-gray-800 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" @onclick="GenerateRandomPassword">New Password</button>
</div>
</div>
</div>
@@ -106,7 +117,7 @@ else
<div class="col">
<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
- <h3 class="mb-4 text-xl font-semibold dark:text-white">Identity</h3>
+ <h3 class="mb-4 text-xl font-semibold dark:text-white">Alias</h3>
<div class="grid gap-6">
<div class="col-span-6 sm:col-span-3">
<EditFormRow Id="first-name" Label="First Name" @bind-Value="Obj.Alias.FirstName"></EditFormRow>
@@ -126,8 +137,6 @@ else
</div>
</div>
</div>
-
- <button type="submit" class="px-4 py-2 text-white bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-300 dark:bg-green-500 dark:hover:bg-green-600 dark:focus:ring-green-800">Save Credentials</button>
</div>
</div>
</div>
@@ -142,6 +151,7 @@ else
public Guid? Id { get; set; }
private bool EditMode { get; set; }
+ private EditForm EditFormRef { get; set; } = null!;
private bool Loading { get; set; } = true;
private CredentialEdit Obj { get; set; } = new();
@@ -228,7 +238,7 @@ else
StateHasChanged();
}
- private async Task GenerateRandomIdentity()
+ private async Task GenerateRandomAlias()
{
GlobalLoadingSpinner.Show();
StateHasChanged();
@@ -239,6 +249,38 @@ else
StateHasChanged();
}
+ /// <summary>
+ /// Generate a new random username based on existing identity, or if no identity is present,
+ /// generate a new random identity.
+ /// </summary>
+ private async Task GenerateRandomUsername()
+ {
+ // If current object is null, then we create a new random identity.
+ Identity identity;
+ if (Obj.Alias.FirstName is null && Obj.Alias.LastName is null && Obj.Alias.BirthDate == DateTime.MinValue)
+ {
+ identity = await IdentityGeneratorFactory.CreateIdentityGenerator(DbService.Settings.DefaultIdentityLanguage).GenerateRandomIdentityAsync();
+ }
+ else
+ {
+ // Assemble identity model with the current values
+ identity = new Identity
+ {
+ FirstName = Obj.Alias.FirstName ?? string.Empty,
+ LastName = Obj.Alias.LastName ?? string.Empty,
+ BirthDate = Obj.Alias.BirthDate,
+ Gender = Obj.Alias.Gender == Gender.Female.ToString() ? Gender.Female : Gender.Male,
+ NickName = Obj.Alias.NickName ?? string.Empty,
+ };
+ }
+
+ var generator = new UsernameEmailGenerator();
+ Obj.Username = generator.GenerateUsername(identity);
+ }
+
+ /// <summary>
+ /// Generate a new random password.
+ /// </summary>
private void GenerateRandomPassword()
{
Obj.Password.Value = CredentialService.GenerateRandomPassword();
@@ -289,25 +331,38 @@ else
/// </summary>
private CredentialEdit CredentialToCredentialEdit(Credential alias)
{
+ // Create a deep copy of the alias object to prevent changes to the original object
+ // when editing the alias in the form. We only want to save the changes when the user
+ // clicks the save button.
+ var options = new JsonSerializerOptions
+ {
+ ReferenceHandler = ReferenceHandler.Preserve,
+ MaxDepth = 128 // Adjust this value as needed
+ };
+
+ // Create a deep copy of the credential object
+ var aliasJson = JsonSerializer.Serialize(alias, options);
+ var aliasCopy = JsonSerializer.Deserialize<Credential>(aliasJson, options)!;
+
return new CredentialEdit
{
- Id = alias.Id,
- Notes = alias.Notes ?? string.Empty,
- Username = alias.Username,
- ServiceName = alias.Service.Name ?? string.Empty,
- ServiceUrl = alias.Service.Url,
- ServiceLogo = alias.Service.Logo,
- Password = alias.Passwords.FirstOrDefault() ?? new Password
+ Id = aliasCopy.Id,
+ Notes = aliasCopy.Notes ?? string.Empty,
+ Username = aliasCopy.Username ?? string.Empty,
+ ServiceName = aliasCopy.Service.Name ?? string.Empty,
+ ServiceUrl = aliasCopy.Service.Url,
+ ServiceLogo = aliasCopy.Service.Logo,
+ Password = aliasCopy.Passwords.FirstOrDefault() ?? new Password
{
Value = string.Empty,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
},
- Alias = alias.Alias,
- AliasBirthDate = alias.Alias.BirthDate.ToString("yyyy-MM-dd"),
- Attachments = alias.Attachments.ToList(),
- CreateDate = alias.CreatedAt,
- LastUpdate = alias.UpdatedAt
+ Alias = aliasCopy.Alias,
+ AliasBirthDate = aliasCopy.Alias.BirthDate.ToString("yyyy-MM-dd"),
+ Attachments = aliasCopy.Attachments.ToList(),
+ CreateDate = aliasCopy.CreatedAt,
+ LastUpdate = aliasCopy.UpdatedAt
};
}
@@ -346,4 +401,25 @@ else
return credential;
}
+
+ /// <summary>
+ /// Cancel the edit operation and navigate back to the credentials view.
+ /// </summary>
+ private void Cancel()
+ {
+ NavigationManager.NavigateTo("/credentials/" + Id);
+ }
+
+ /// <summary>
+ /// Trigger the form submit.
+ /// </summary>
+ private async Task TriggerFormSubmit()
+ {
+ if (EditFormRef.EditContext?.Validate() == false)
+ {
+ return;
+ }
+
+ await SaveAlias();
+ }
}
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/View.razor b/src/AliasVault.Client/Main/Pages/Credentials/View.razor
index 48e5ca208..908e58674 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/View.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/View.razor
@@ -74,11 +74,11 @@ else
</form>
</div>
<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
- <h3 class="mb-4 text-xl font-semibold dark:text-white">Name</h3>
+ <h3 class="mb-4 text-xl font-semibold dark:text-white">Alias</h3>
<form action="#">
<div class="grid grid-cols-6 gap-6">
- <div class="col-span-6 sm:col-span-3">
- <CopyPasteFormRow Label="Initials" Value="@(Alias.Alias.FirstName?.Substring(0,1))"></CopyPasteFormRow>
+ <div class="col-span-6">
+ <CopyPasteFormRow Label="Full name" Value="@(Alias.Alias.FirstName + " " + Alias.Alias.LastName)"></CopyPasteFormRow>
</div>
<div class="col-span-6 sm:col-span-3">
<CopyPasteFormRow Label="First name" Value="@(Alias.Alias.FirstName)"></CopyPasteFormRow>
diff --git a/src/AliasVault.Client/Main/Pages/Emails/Home.razor b/src/AliasVault.Client/Main/Pages/Emails/Home.razor
index cb578b899..61d33d93e 100644
--- a/src/AliasVault.Client/Main/Pages/Emails/Home.razor
+++ b/src/AliasVault.Client/Main/Pages/Emails/Home.razor
@@ -44,7 +44,7 @@ else
@foreach (var email in EmailList)
{
<li class="hover:bg-gray-50 transition duration-150 ease-in-out">
- <div @onclick="() => ShowAliasVaultEmailInModal(email.Id)" class="block p-4 flex justify-start items-start">
+ <div @onclick="() => ShowAliasVaultEmailInModal(email.Id)" class="p-4 flex justify-start items-start">
<div class="mr-4 flex-shrink-0">
<SenderInitials SenderName="@email.FromName" SenderEmail="@email.FromEmail" />
</div>
@@ -188,9 +188,10 @@ else
var credentialLookup = await context.Credentials
.Include(x => x.Service)
.Include(x => x.Alias)
+ .GroupBy(x => x.Alias.Email!.ToLower())
.ToDictionaryAsync(
- x => x.Alias.Email?.ToLower() ?? string.Empty,
- x => new { x.Id, ServiceName = x.Service.Name ?? "Unknown" }
+ g => g.Key,
+ g => new { Id = g.First().Id, ServiceName = g.First().Service.Name ?? "Unknown" }
);
// Convert the email list to view models and add credential info in a single pass
diff --git a/src/AliasVault.Client/Main/Pages/Settings/General.razor b/src/AliasVault.Client/Main/Pages/Settings/General.razor
index 6dd395f88..0652977a7 100644
--- a/src/AliasVault.Client/Main/Pages/Settings/General.razor
+++ b/src/AliasVault.Client/Main/Pages/Settings/General.razor
@@ -45,10 +45,10 @@
</div>
<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
- <h3 class="mb-4 text-lg font-medium text-gray-900 dark:text-white">Identity Settings</h3>
+ <h3 class="mb-4 text-lg font-medium text-gray-900 dark:text-white">Alias Settings</h3>
<div class="mb-4">
- <label for="defaultEmailDomain" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Identity generation language</label>
+ <label for="defaultEmailDomain" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Alias generation language</label>
<select @bind="DefaultIdentityLanguage" @bind:after="UpdateDefaultIdentityLanguage" id="defaultIdentityLanguage" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option value="en">English</option>
<option value="nl">Dutch</option>
diff --git a/src/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs b/src/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
index 1dd8e129d..897bcf767 100644
--- a/src/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
+++ b/src/AliasVault.Client/Services/Auth/AliasVaultApiHandlerService.cs
@@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Components;
/// This services handles all API requests to the AliasVault API and will add the access token to the request headers.
/// If a 401 unauthorized is returned by the API it will intercept this response and attempt to automatically refresh the access token.
/// </summary>
-public class AliasVaultApiHandlerService(IServiceProvider serviceProvider) : DelegatingHandler
+public sealed class AliasVaultApiHandlerService(IServiceProvider serviceProvider) : DelegatingHandler
{
/// <summary>
/// Override the SendAsync method to add the access token to the request headers.
diff --git a/src/AliasVault.Client/Services/Auth/AuthService.cs b/src/AliasVault.Client/Services/Auth/AuthService.cs
index 72fb32275..0b99b1207 100644
--- a/src/AliasVault.Client/Services/Auth/AuthService.cs
+++ b/src/AliasVault.Client/Services/Auth/AuthService.cs
@@ -17,14 +17,11 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
/// This service is responsible for handling authentication-related operations such as refreshing tokens,
/// storing tokens, and revoking tokens.
/// </summary>
-/// <remarks>
-/// Initializes a new instance of the <see cref="AuthService"/> class.
-/// </remarks>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="localStorage">The local storage service.</param>
/// <param name="environment">IWebAssemblyHostEnvironment instance.</param>
/// <param name="configuration">IConfiguration instance.</param>
-public class AuthService(HttpClient httpClient, ILocalStorageService localStorage, IWebAssemblyHostEnvironment environment, IConfiguration configuration)
+public sealed class AuthService(HttpClient httpClient, ILocalStorageService localStorage, IWebAssemblyHostEnvironment environment, IConfiguration configuration)
{
private const string AccessTokenKey = "token";
private const string RefreshTokenKey = "refreshToken";
diff --git a/src/AliasVault.Client/Services/ClipboardCopyService.cs b/src/AliasVault.Client/Services/ClipboardCopyService.cs
index e3ff0489f..ea421e995 100644
--- a/src/AliasVault.Client/Services/ClipboardCopyService.cs
+++ b/src/AliasVault.Client/Services/ClipboardCopyService.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Client.Services;
/// <summary>
/// Service to manage the clipboard copy operations across the application.
/// </summary>
-public class ClipboardCopyService
+public sealed class ClipboardCopyService
{
private string _currentCopiedId = string.Empty;
diff --git a/src/AliasVault.Client/Services/CredentialService.cs b/src/AliasVault.Client/Services/CredentialService.cs
index b7b755794..3099c2636 100644
--- a/src/AliasVault.Client/Services/CredentialService.cs
+++ b/src/AliasVault.Client/Services/CredentialService.cs
@@ -16,7 +16,6 @@ using System.Threading.Tasks;
using AliasClientDb;
using AliasGenerators.Identity.Implementations;
using AliasGenerators.Identity.Models;
-using AliasGenerators.Password;
using AliasGenerators.Password.Implementations;
using AliasVault.Shared.Models;
using Microsoft.EntityFrameworkCore;
@@ -25,7 +24,7 @@ using Identity = AliasGenerators.Identity.Models.Identity;
/// <summary>
/// Service class for alias operations.
/// </summary>
-public class CredentialService(HttpClient httpClient, DbService dbService, Config config)
+public sealed class CredentialService(HttpClient httpClient, DbService dbService, Config config)
{
/// <summary>
/// Generates a random password for a credential.
@@ -120,6 +119,13 @@ public class CredentialService(HttpClient httpClient, DbService dbService, Confi
// Try to extract favicon from service URL
await ExtractFaviconAsync(loginObject);
+ if (loginObject.Alias.Email is not null && loginObject.Alias.Email.StartsWith("@"))
+ {
+ // If the email starts with an @ it is most likely still the placeholder which hasn't been filled.
+ // So we remove it.
+ loginObject.Alias.Email = null;
+ }
+
var login = new Credential
{
CreatedAt = DateTime.UtcNow,
@@ -189,6 +195,14 @@ public class CredentialService(HttpClient httpClient, DbService dbService, Confi
throw new InvalidOperationException("Login object not found.");
}
+ // Sanitize email address.
+ // If the email starts with an @ it is most likely still the placeholder which hasn't been filled.
+ // So we remove it.
+ if (loginObject.Alias.Email is not null && loginObject.Alias.Email.StartsWith("@"))
+ {
+ loginObject.Alias.Email = null;
+ }
+
login.UpdatedAt = DateTime.UtcNow;
login.Notes = loginObject.Notes;
login.Username = loginObject.Username;
diff --git a/src/AliasVault.Client/Services/Database/DbService.cs b/src/AliasVault.Client/Services/Database/DbService.cs
index 0a1f8a2a9..329da1ed0 100644
--- a/src/AliasVault.Client/Services/Database/DbService.cs
+++ b/src/AliasVault.Client/Services/Database/DbService.cs
@@ -20,7 +20,7 @@ using Microsoft.EntityFrameworkCore;
/// with a AliasClientDb database instance that is only persisted in memory due to the encryption requirements of the
/// database itself. The database should not be persisted to disk when in un-encrypted form.
/// </summary>
-public class DbService : IDisposable
+public sealed class DbService : IDisposable
{
private readonly AuthService _authService;
private readonly JsInteropService _jsInteropService;
@@ -311,7 +311,7 @@ public class DbService : IDisposable
/// Disposes the service.
/// </summary>
/// <param name="disposing">True if disposing.</param>
- protected virtual void Dispose(bool disposing)
+ public void Dispose(bool disposing)
{
if (_disposed)
{
diff --git a/src/AliasVault.Client/Services/Database/DbServiceState.cs b/src/AliasVault.Client/Services/Database/DbServiceState.cs
index b8a1234a9..2d7669612 100644
--- a/src/AliasVault.Client/Services/Database/DbServiceState.cs
+++ b/src/AliasVault.Client/Services/Database/DbServiceState.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Client.Services.Database;
/// <summary>
/// Class to manage the state of the AliasClientDbService that others can subscribe to events for.
/// </summary>
-public class DbServiceState
+public sealed class DbServiceState
{
private DatabaseState _currentState = new();
@@ -114,7 +114,7 @@ public class DbServiceState
/// OnStateChanged event handler.
/// </summary>
/// <param name="newState">The new state.</param>
- protected virtual void OnStateChanged(DatabaseState newState)
+ private void OnStateChanged(DatabaseState newState)
{
StateChanged?.Invoke(this, newState);
}
diff --git a/src/AliasVault.Client/Services/EmailService.cs b/src/AliasVault.Client/Services/EmailService.cs
index 86fc15f4d..246ef9a57 100644
--- a/src/AliasVault.Client/Services/EmailService.cs
+++ b/src/AliasVault.Client/Services/EmailService.cs
@@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore;
/// <summary>
/// Email service that contains utility methods for handling email functionality such as client-side decryption.
/// </summary>
-public class EmailService(DbService dbService, JsInteropService jsInteropService, GlobalNotificationService globalNotificationService)
+public sealed class EmailService(DbService dbService, JsInteropService jsInteropService, GlobalNotificationService globalNotificationService)
{
private List<EncryptionKey> _encryptionKeys = [];
diff --git a/src/AliasVault.Client/Services/GlobalLoadingService.cs b/src/AliasVault.Client/Services/GlobalLoadingService.cs
index 0380319f5..afc3c51c4 100644
--- a/src/AliasVault.Client/Services/GlobalLoadingService.cs
+++ b/src/AliasVault.Client/Services/GlobalLoadingService.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Client.Services;
/// <summary>
/// Global loading service that can be used to show or hide a global layout loading spinner.
/// </summary>
-public class GlobalLoadingService
+public sealed class GlobalLoadingService
{
private bool _isLoading;
diff --git a/src/AliasVault.Client/Services/GlobalNotificationService.cs b/src/AliasVault.Client/Services/GlobalNotificationService.cs
index 0b8ad5f50..3a86a190a 100644
--- a/src/AliasVault.Client/Services/GlobalNotificationService.cs
+++ b/src/AliasVault.Client/Services/GlobalNotificationService.cs
@@ -12,7 +12,7 @@ namespace AliasVault.Client.Services;
/// are stored in this object which is scoped to the current session. This allows the messages to be cached until
/// they actually have been displayed. So they can survive redirects and page reloads.
/// </summary>
-public class GlobalNotificationService
+public sealed class GlobalNotificationService
{
/// <summary>
/// Allow other components to subscribe to changes in the event object.
@@ -22,12 +22,12 @@ public class GlobalNotificationService
/// <summary>
/// Gets success messages that should be displayed to the user.
/// </summary>
- protected List<string> SuccessMessages { get; } = [];
+ private List<string> SuccessMessages { get; } = [];
/// <summary>
/// Gets error messages that should be displayed to the user.
/// </summary>
- protected List<string> ErrorMessages { get; } = [];
+ private List<string> ErrorMessages { get; } = [];
/// <summary>
/// Adds a success message to the list of messages that should be displayed to the user.
diff --git a/src/AliasVault.Client/Services/JsInteropService.cs b/src/AliasVault.Client/Services/JsInteropService.cs
index 8d6c583b8..984b5ace9 100644
--- a/src/AliasVault.Client/Services/JsInteropService.cs
+++ b/src/AliasVault.Client/Services/JsInteropService.cs
@@ -15,7 +15,7 @@ using Microsoft.JSInterop;
/// JavaScript interop service for calling JavaScript functions from C#.
/// </summary>
/// <param name="jsRuntime">IJSRuntime.</param>
-public class JsInteropService(IJSRuntime jsRuntime)
+public sealed class JsInteropService(IJSRuntime jsRuntime)
{
/// <summary>
/// Symmetrically encrypts a string using the provided encryption key.
diff --git a/src/AliasVault.Client/Services/KeyboardShortcutService.cs b/src/AliasVault.Client/Services/KeyboardShortcutService.cs
index 4fead2f27..ffcf7149b 100644
--- a/src/AliasVault.Client/Services/KeyboardShortcutService.cs
+++ b/src/AliasVault.Client/Services/KeyboardShortcutService.cs
@@ -15,7 +15,7 @@ using Microsoft.JSInterop;
/// <summary>
/// Service class for alias operations.
/// </summary>
-public class KeyboardShortcutService : IAsyncDisposable
+public sealed class KeyboardShortcutService : IAsyncDisposable
{
private readonly DotNetObjectReference<CallbackWrapper> _dotNetHelper;
private readonly NavigationManager _navigationManager;
@@ -87,6 +87,13 @@ public class KeyboardShortcutService : IAsyncDisposable
_navigationManager.NavigateTo("/");
return Task.CompletedTask;
});
+
+ // Global shortcut: Go to email page
+ await RegisterShortcutAsync("ge", () =>
+ {
+ _navigationManager.NavigateTo("/emails");
+ return Task.CompletedTask;
+ });
}
/// <summary>
diff --git a/src/AliasVault.Client/Services/SettingsService.cs b/src/AliasVault.Client/Services/SettingsService.cs
index 30ba2722a..a54b076be 100644
--- a/src/AliasVault.Client/Services/SettingsService.cs
+++ b/src/AliasVault.Client/Services/SettingsService.cs
@@ -20,7 +20,7 @@ using Microsoft.EntityFrameworkCore;
/// This is done because the SettingsService requires a DbContext during initialization and the context is not yet
/// available during application boot because of encryption/decryption of remote database file. When accessing the
/// settings through the DbService we can ensure proper data flow.</remarks>
-public class SettingsService
+public sealed class SettingsService
{
private readonly Dictionary<string, string?> _settings = new();
private DbService? _dbService;
diff --git a/src/AliasVault.Client/wwwroot/css/tailwind.css b/src/AliasVault.Client/wwwroot/css/tailwind.css
index fe785f627..57f79b764 100644
--- a/src/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/src/AliasVault.Client/wwwroot/css/tailwind.css
@@ -648,6 +648,10 @@ video {
grid-column: 1 / -1;
}
+.col-span-12 {
+ grid-column: span 12 / span 12;
+}
+
.mx-4 {
margin-left: 1rem;
margin-right: 1rem;
diff --git a/src/Databases/AliasClientDb/Credential.cs b/src/Databases/AliasClientDb/Credential.cs
index 766bb1f27..db3a3becc 100644
--- a/src/Databases/AliasClientDb/Credential.cs
+++ b/src/Databases/AliasClientDb/Credential.cs
@@ -39,7 +39,7 @@ public class Credential
/// <summary>
/// Gets or sets the username field.
/// </summary>
- public string Username { get; set; } = null!;
+ public string? Username { get; set; }
/// <summary>
/// Gets or sets the password objects.
diff --git a/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.Designer.cs b/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.Designer.cs
new file mode 100644
index 000000000..fa3ef692f
--- /dev/null
+++ b/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.Designer.cs
@@ -0,0 +1,295 @@
+// <auto-generated />
+using System;
+using AliasClientDb;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace AliasClientDb.Migrations
+{
+ [DbContext(typeof(AliasClientDbContext))]
+ [Migration("20240812141727_1.3.1-MakeUsernameOptional")]
+ partial class _131MakeUsernameOptional
+ {
+ /// <inheritdoc />
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.7")
+ .HasAnnotation("Proxies:ChangeTracking", false)
+ .HasAnnotation("Proxies:CheckEquality", false)
+ .HasAnnotation("Proxies:LazyLoading", true);
+
+ modelBuilder.Entity("AliasClientDb.Alias", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("BirthDate")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Email")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("FirstName")
+ .HasMaxLength(255)
+ .HasColumnType("VARCHAR");
+
+ b.Property<string>("Gender")
+ .HasMaxLength(255)
+ .HasColumnType("VARCHAR");
+
+ b.Property<string>("LastName")
+ .HasMaxLength(255)
+ .HasColumnType("VARCHAR");
+
+ b.Property<string>("NickName")
+ .HasMaxLength(255)
+ .HasColumnType("VARCHAR");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Aliases");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Attachment", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<byte[]>("Blob")
+ .IsRequired()
+ .HasColumnType("BLOB");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<Guid>("CredentialId")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Filename")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CredentialId");
+
+ b.ToTable("Attachment");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Credential", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<Guid>("AliasId")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Notes")
+ .HasColumnType("TEXT");
+
+ b.Property<Guid>("ServiceId")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Username")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AliasId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("Credentials");
+ });
+
+ modelBuilder.Entity("AliasClientDb.EncryptionKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("PrivateKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("EncryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Password", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<Guid>("CredentialId")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Value")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CredentialId");
+
+ b.ToTable("Passwords");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Service", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<byte[]>("Logo")
+ .HasColumnType("BLOB");
+
+ b.Property<string>("Name")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Url")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Services");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Setting", b =>
+ {
+ b.Property<string>("Key")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Value")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Key");
+
+ b.ToTable("Settings");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Attachment", b =>
+ {
+ b.HasOne("AliasClientDb.Credential", "Credential")
+ .WithMany("Attachments")
+ .HasForeignKey("CredentialId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Credential");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Credential", b =>
+ {
+ b.HasOne("AliasClientDb.Alias", "Alias")
+ .WithMany("Credentials")
+ .HasForeignKey("AliasId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasClientDb.Service", "Service")
+ .WithMany("Credentials")
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Alias");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Password", b =>
+ {
+ b.HasOne("AliasClientDb.Credential", "Credential")
+ .WithMany("Passwords")
+ .HasForeignKey("CredentialId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Credential");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Alias", b =>
+ {
+ b.Navigation("Credentials");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Credential", b =>
+ {
+ b.Navigation("Attachments");
+
+ b.Navigation("Passwords");
+ });
+
+ modelBuilder.Entity("AliasClientDb.Service", b =>
+ {
+ b.Navigation("Credentials");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.cs b/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.cs
new file mode 100644
index 000000000..1142a2a5c
--- /dev/null
+++ b/src/Databases/AliasClientDb/Migrations/20240812141727_1.3.1-MakeUsernameOptional.cs
@@ -0,0 +1,37 @@
+// <auto-generated />
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasClientDb.Migrations
+{
+ /// <inheritdoc />
+ public partial class _131MakeUsernameOptional : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn<string>(
+ name: "Username",
+ table: "Credentials",
+ type: "TEXT",
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "TEXT");
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn<string>(
+ name: "Username",
+ table: "Credentials",
+ type: "TEXT",
+ nullable: false,
+ defaultValue: "",
+ oldClrType: typeof(string),
+ oldType: "TEXT",
+ oldNullable: true);
+ }
+ }
+}
diff --git a/src/Databases/AliasClientDb/Migrations/AliasClientDbContextModelSnapshot.cs b/src/Databases/AliasClientDb/Migrations/AliasClientDbContextModelSnapshot.cs
index 29dbdec70..66d5c317b 100644
--- a/src/Databases/AliasClientDb/Migrations/AliasClientDbContextModelSnapshot.cs
+++ b/src/Databases/AliasClientDb/Migrations/AliasClientDbContextModelSnapshot.cs
@@ -114,7 +114,6 @@ namespace AliasClientDb.Migrations
.HasColumnType("TEXT");
b.Property<string>("Username")
- .IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
index db4d4b81b..52d150d11 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
@@ -139,18 +139,25 @@ public class CredentialTest : ClientPlaywrightTest
{ "service-name", serviceName },
});
- // Wait for button with text "Generate Random Identity" to appear.
- var generateButton = Page.Locator("text=Generate Random Identity");
- Assert.That(generateButton, Is.Not.Null, "Generate button not found.");
+ // 1. First try to generate new username with no identity fields set yet.
+ var newUsernameButton = Page.Locator("text=New Username").First;
+ Assert.That(newUsernameButton, Is.Not.Null, "Generate button not found.");
+ await newUsernameButton.ClickAsync();
+ await Task.Delay(100);
+
+ var username = await Page.InputValueAsync("#username");
+ Assert.That(username, Is.Not.Null.And.Not.Empty, "Username not generated before alias is generated.");
- // Press the button to generate a random identity.
+ // 2. Then generate a new identity.
+ var generateButton = Page.Locator("text=Generate Random Alias");
+ Assert.That(generateButton, Is.Not.Null, "Generate button not found.");
await generateButton.First.ClickAsync();
// Wait for the identity fields to be filled.
- await Task.Delay(1000);
+ await Task.Delay(100);
// Verify that the identity fields are filled.
- var username = await Page.InputValueAsync("#username");
+ username = await Page.InputValueAsync("#username");
var firstName = await Page.InputValueAsync("#first-name");
var lastName = await Page.InputValueAsync("#last-name");
@@ -161,5 +168,13 @@ public class CredentialTest : ClientPlaywrightTest
Assert.That(firstName, Is.Not.Null.And.Not.Empty, "First name not generated.");
Assert.That(lastName, Is.Not.Null.And.Not.Empty, "Last name not generated.");
});
+
+ // 3. Regenerate the username field again.
+ newUsernameButton = Page.Locator("text=New Username").First;
+ await newUsernameButton.ClickAsync();
+
+ await Task.Delay(100);
+ username = await Page.InputValueAsync("#username");
+ Assert.That(username, Is.Not.Null.And.Not.Empty, "Username not generated after alias is generated.");
}
}