Skip to content

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

Add birthdate minvalue filter to main client UI (#746)

Leendert de Borste665130ea70d
diff --git a/src/AliasVault.Client/Main/Models/CredentialEdit.cs b/src/AliasVault.Client/Main/Models/CredentialEdit.cs
index 9ec5c230d..b6515c147 100644
--- a/src/AliasVault.Client/Main/Models/CredentialEdit.cs
+++ b/src/AliasVault.Client/Main/Models/CredentialEdit.cs
@@ -59,9 +59,9 @@ public sealed class CredentialEdit
public Alias Alias { get; set; } = null!;
/// <summary>
- /// Gets or sets the Alias BirthDate.
+ /// Gets or sets the Alias BirthDate. Can be empty string or a date in yyyy-MM-dd format.
/// </summary>
- [StringDateFormat("yyyy-MM-dd")]
+ [StringDateFormat("yyyy-MM-dd", AllowEmpty = true)]
public string AliasBirthDate { get; set; } = string.Empty;
/// <summary>
@@ -122,7 +122,7 @@ public sealed class CredentialEdit
UpdatedAt = DateTime.UtcNow,
},
Alias = credentialCopy.Alias,
- AliasBirthDate = credentialCopy.Alias.BirthDate.ToString("yyyy-MM-dd"),
+ AliasBirthDate = credentialCopy.Alias.BirthDate == DateTime.MinValue ? string.Empty : credentialCopy.Alias.BirthDate.ToString("yyyy-MM-dd"),
Attachments = credentialCopy.Attachments.ToList(),
TotpCodes = credentialCopy.TotpCodes.ToList(),
CreateDate = credentialCopy.CreatedAt,
@@ -147,10 +147,10 @@ public sealed class CredentialEdit
Url = ServiceUrl,
Logo = ServiceLogo,
},
- Passwords = new List<Password>
- {
+ Passwords =
+ [
Password,
- },
+ ],
Alias = Alias,
Attachments = Attachments,
TotpCodes = TotpCodes,
diff --git a/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs b/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
index c087ab515..b9ef6cc06 100644
--- a/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
+++ b/src/AliasVault.Client/Main/Models/FormValidation/StringDateFormatAttribute.cs
@@ -19,6 +19,11 @@ using System.Globalization;
/// <param name="format">The date format to validate.</param>
public sealed class StringDateFormatAttribute(string format) : ValidationAttribute
{
+ /// <summary>
+ /// Gets or sets a value indicating whether empty strings should be considered valid.
+ /// </summary>
+ public bool AllowEmpty { get; set; } = false;
+
/// <summary>
/// Check if the date string is in the correct format.
/// </summary>
@@ -27,9 +32,17 @@ public sealed class StringDateFormatAttribute(string format) : ValidationAttribu
/// <returns>ValidationResult.</returns>
protected override ValidationResult IsValid(object? value, ValidationContext validationContext)
{
- if (value is string dateString && DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
+ if (value is string dateString)
{
- return ValidationResult.Success!;
+ if (string.IsNullOrWhiteSpace(dateString) && AllowEmpty)
+ {
+ return ValidationResult.Success!;
+ }
+
+ if (DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
+ {
+ return ValidationResult.Success!;
+ }
}
return new ValidationResult($"The date must be in the format {format}.", [validationContext.MemberName!]);
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
index 6a7ce9980..7ec3a790c 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
@@ -192,44 +192,14 @@ else
if (firstRender)
{
Module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/modules/newIdentityWidget.js");
+
if (EditMode)
{
- if (Id is null)
- {
- // Error loading alias.
- GlobalNotificationService.AddErrorMessage("This credential does not exist (anymore). Please try again.");
- NavigationManager.NavigateTo("/", false, true);
- return;
- }
-
- // Load existing Obj, retrieve from service
- var alias = await CredentialService.LoadEntryAsync(Id.Value);
- if (alias is null)
- {
- // Error loading alias.
- GlobalNotificationService.AddErrorMessage("This credential does not exist (anymore). Please try again.");
- NavigationManager.NavigateTo("/", false, true);
- return;
- }
-
- Obj = CredentialEdit.FromEntity(alias);
- if (Obj.ServiceUrl is null)
- {
- Obj.ServiceUrl = CredentialService.DefaultServiceUrl;
- }
+ await LoadExistingCredential();
}
else
{
- // Create new Obj
- var alias = new Credential();
- alias.Alias = new Alias();
- alias.Alias.Email = "@" + CredentialService.GetDefaultEmailDomain();
- alias.Service = new Service();
- alias.Passwords = new List<Password> { new Password() };
- alias.TotpCodes = new List<TotpCode>();
-
- Obj = CredentialEdit.FromEntity(alias);
- Obj.ServiceUrl = CredentialService.DefaultServiceUrl;
+ CreateNewCredential();
}
Loading = false;
@@ -243,6 +213,73 @@ else
}
}
+ /// <summary>
+ /// Loads an existing credential for editing.
+ /// </summary>
+ private async Task LoadExistingCredential()
+ {
+ if (Id is null)
+ {
+ NavigateAwayWithError("This credential does not exist (anymore). Please try again.");
+ return;
+ }
+
+ // Load existing Obj, retrieve from service
+ var alias = await CredentialService.LoadEntryAsync(Id.Value);
+ if (alias is null)
+ {
+ NavigateAwayWithError("This credential does not exist (anymore). Please try again.");
+ return;
+ }
+
+ Obj = CredentialEdit.FromEntity(alias);
+
+ // If BirthDate is MinValue, set AliasBirthDate to empty string
+ // TODO: after date field in alias data model is made optional and
+ // all min values have been replaced with null, we can remove this check.
+ if (Obj.Alias.BirthDate == DateTime.MinValue)
+ {
+ Obj.AliasBirthDate = string.Empty;
+ }
+
+ if (Obj.ServiceUrl is null)
+ {
+ Obj.ServiceUrl = CredentialService.DefaultServiceUrl;
+ }
+ }
+
+ /// <summary>
+ /// Creates a new credential object.
+ /// </summary>
+ private void CreateNewCredential()
+ {
+ // Create new Obj
+ var alias = new Credential();
+ alias.Alias = new Alias();
+ alias.Alias.Email = "@" + CredentialService.GetDefaultEmailDomain();
+ alias.Service = new Service();
+ alias.Passwords = new List<Password> { new Password() };
+ alias.TotpCodes = new List<TotpCode>();
+
+ Obj = CredentialEdit.FromEntity(alias);
+
+ // Always set AliasBirthDate to empty for new credentials
+ // TODO: after date field in alias data model is made optional and
+ // all min values have been replaced with null, we can remove this check.
+ Obj.AliasBirthDate = string.Empty;
+
+ Obj.ServiceUrl = CredentialService.DefaultServiceUrl;
+ }
+
+ /// <summary>
+ /// Adds an error message and navigates to the home page.
+ /// </summary>
+ private void NavigateAwayWithError(string errorMessage)
+ {
+ GlobalNotificationService.AddErrorMessage(errorMessage);
+ NavigationManager.NavigateTo("/", false, true);
+ }
+
/// <summary>
/// When the URL input is focused, place cursor at the end of the default URL to allow for easy typing.
/// </summary>
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/View.razor b/src/AliasVault.Client/Main/Pages/Credentials/View.razor
index 4f9727ada..a116f8eab 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/View.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/View.razor
@@ -154,7 +154,7 @@ else
/// </summary>
/// <param name="date">The date to check.</param>
/// <returns>True if the date is valid and not a min value, false otherwise.</returns>
- private bool IsValidDate(DateTime date)
+ private static bool IsValidDate(DateTime date)
{
// Check if date is min value (year 1 or 0001-01-01)
if (date.Year <= 1 || date.ToString("yyyy-MM-dd") == "0001-01-01")