Skip to content

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

Refactor client form model validation messages and add missing translations (#1153)

Leendert de Borst6a75e56123cf
diff --git a/apps/server/AliasVault.Client/Auth/Models/LoginFormModel.cs b/apps/server/AliasVault.Client/Auth/Models/LoginFormModel.cs
index f2b868e96..5519a598a 100644
--- a/apps/server/AliasVault.Client/Auth/Models/LoginFormModel.cs
+++ b/apps/server/AliasVault.Client/Auth/Models/LoginFormModel.cs
@@ -9,36 +9,26 @@ namespace AliasVault.Client.Auth.Models;
using System.ComponentModel.DataAnnotations;
using AliasVault.Client.Resources;
-using AliasVault.Shared.Models.WebApi.Auth;
/// <summary>
/// Login form model with localized validation.
/// </summary>
-public class LoginFormModel : LoginModel
+public class LoginFormModel
{
/// <summary>
/// Gets or sets the username.
/// </summary>
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.UsernameRequired))]
- public new string Username { get; set; } = null!;
+ public string Username { get; set; } = null!;
/// <summary>
/// Gets or sets the password.
/// </summary>
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordRequired))]
- public new string Password { get; set; } = null!;
+ public string Password { get; set; } = null!;
/// <summary>
- /// Converts the form model to the base model.
+ /// Gets or sets a value indicating whether the user wants to be remembered.
/// </summary>
- /// <returns>The base LoginModel.</returns>
- public LoginModel ToBaseModel()
- {
- return new LoginModel
- {
- Username = Username,
- Password = Password,
- RememberMe = RememberMe,
- };
- }
+ public bool RememberMe { get; set; } = true;
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel2Fa.cs b/apps/server/AliasVault.Client/Auth/Models/LoginModel2Fa.cs
similarity index 81%
rename from apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel2Fa.cs
rename to apps/server/AliasVault.Client/Auth/Models/LoginModel2Fa.cs
index fcf47dbb7..26471df42 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel2Fa.cs
+++ b/apps/server/AliasVault.Client/Auth/Models/LoginModel2Fa.cs
@@ -5,9 +5,10 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Shared.Models.WebApi.Auth;
+namespace AliasVault.Client.Auth.Models;
using System.ComponentModel.DataAnnotations;
+using AliasVault.Client.Resources;
/// <summary>
/// Login model for 2-factor authentication step using an authenticator code.
@@ -17,7 +18,7 @@ public class LoginModel2Fa
/// <summary>
/// Gets or sets the 2-factor code.
/// </summary>
- [Required]
+ [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.FieldRequired))]
[Display(Name = "Authenticator Code")]
public int? TwoFactorCode { get; set; }
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModelRecoveryCode.cs b/apps/server/AliasVault.Client/Auth/Models/LoginModelRecoveryCode.cs
similarity index 76%
rename from apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModelRecoveryCode.cs
rename to apps/server/AliasVault.Client/Auth/Models/LoginModelRecoveryCode.cs
index 251da6f59..0bf23dd68 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModelRecoveryCode.cs
+++ b/apps/server/AliasVault.Client/Auth/Models/LoginModelRecoveryCode.cs
@@ -5,9 +5,10 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Shared.Models.WebApi.Auth;
+namespace AliasVault.Client.Auth.Models;
using System.ComponentModel.DataAnnotations;
+using AliasVault.Client.Resources;
/// <summary>
/// Login model for two factor authentication step using a recovery code.
@@ -17,6 +18,6 @@ public class LoginModelRecoveryCode
/// <summary>
/// Gets or sets the recovery code.
/// </summary>
- [Required]
+ [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.FieldRequired))]
public string RecoveryCode { get; set; } = null!;
}
diff --git a/apps/server/AliasVault.Client/Auth/Models/RegisterFormModel.cs b/apps/server/AliasVault.Client/Auth/Models/RegisterFormModel.cs
index 49cd025ee..b3773339e 100644
--- a/apps/server/AliasVault.Client/Auth/Models/RegisterFormModel.cs
+++ b/apps/server/AliasVault.Client/Auth/Models/RegisterFormModel.cs
@@ -10,51 +10,35 @@ namespace AliasVault.Client.Auth.Models;
using System.ComponentModel.DataAnnotations;
using AliasVault.Client.Resources;
using AliasVault.Shared.Models.Validation;
-using AliasVault.Shared.Models.WebApi.Auth;
/// <summary>
/// Register form model with validation.
/// </summary>
-public class RegisterFormModel : RegisterModel
+public class RegisterFormModel
{
/// <summary>
/// Gets or sets the username.
/// </summary>
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.UsernameRequired))]
- public new string Username { get; set; } = null!;
+ public string Username { get; set; } = null!;
/// <summary>
/// Gets or sets the password.
/// </summary>
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordRequired))]
[MinLength(8, ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordMinLengthGeneric))]
- public new string Password { get; set; } = null!;
+ public string Password { get; set; } = null!;
/// <summary>
/// Gets or sets the password confirmation.
/// </summary>
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordRequired))]
[Compare("Password", ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordsDoNotMatchGeneric))]
- public new string PasswordConfirm { get; set; } = null!;
+ public string PasswordConfirm { get; set; } = null!;
/// <summary>
/// Gets or sets a value indicating whether the terms and conditions are accepted or not.
/// </summary>
[MustBeTrue(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.MustAcceptTerms))]
- public new bool AcceptTerms { get; set; } = false;
-
- /// <summary>
- /// Converts the form model to the base model.
- /// </summary>
- /// <returns>The base RegisterModel.</returns>
- public RegisterModel ToBaseModel()
- {
- return new RegisterModel
- {
- Username = Username,
- Password = Password,
- PasswordConfirm = PasswordConfirm,
- AcceptTerms = AcceptTerms,
- };
- }
+ public bool AcceptTerms { get; set; } = false;
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/UnlockModel.cs b/apps/server/AliasVault.Client/Auth/Models/UnlockModel.cs
similarity index 69%
rename from apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/UnlockModel.cs
rename to apps/server/AliasVault.Client/Auth/Models/UnlockModel.cs
index 2c81a7196..6bee31f23 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/UnlockModel.cs
+++ b/apps/server/AliasVault.Client/Auth/Models/UnlockModel.cs
@@ -5,18 +5,19 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Shared.Models.WebApi.Auth;
+namespace AliasVault.Client.Auth.Models;
using System.ComponentModel.DataAnnotations;
+using AliasVault.Client.Resources;
/// <summary>
-/// Unlock model.
+/// Unlock model with localized validation.
/// </summary>
public class UnlockModel
{
/// <summary>
/// Gets or sets the password.
/// </summary>
- [Required]
+ [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.PasswordRequired))]
public string Password { get; set; } = null!;
}
diff --git a/apps/server/AliasVault.Client/Auth/Pages/Login.razor b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
index 8f54fa8bc..bd1fd735f 100644
--- a/apps/server/AliasVault.Client/Auth/Pages/Login.razor
+++ b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
@@ -46,7 +46,9 @@
</div>
<p class="mt-6 text-sm text-gray-700 dark:text-gray-300">
@Localizer["DontHaveAuthenticatorText"]
- <button @onclick="LoginWithRecoveryCode" class="text-primary-600 hover:underline dark:text-primary-500">@Localizer["LoginWithRecoveryCodeLink"]</button>.
+ </p>
+ <p class="text-sm text-gray-700 dark:text-gray-300">
+ <button @onclick="LoginWithRecoveryCode" class="text-primary-600 hover:underline dark:text-primary-500">@Localizer["LoginWithRecoveryCodeLink"]</button>
</p>
}
else if (_showLoginWithRecoveryCodeStep)
@@ -73,7 +75,9 @@ else if (_showLoginWithRecoveryCodeStep)
</div>
<p class="mt-6 text-sm text-gray-700 dark:text-gray-300">
@Localizer["RegainedAccessText"]
- <button @onclick="LoginWithAuthenticator" class="text-primary-600 hover:underline dark:text-primary-500">@Localizer["LoginWithAuthenticatorLink"]</button> instead.
+ </p>
+ <p class="text-sm text-gray-700 dark:text-gray-300">
+ <button @onclick="LoginWithAuthenticator" class="text-primary-600 hover:underline dark:text-primary-500">@Localizer["LoginWithAuthenticatorLink"]</button>
</p>
}
else
@@ -448,4 +452,5 @@ else
_serverValidationErrors.Clear();
}
}
+
}
diff --git a/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor b/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
index cf195df76..985db2671 100644
--- a/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
+++ b/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
@@ -5,6 +5,7 @@
@layout Auth.Layout.MainLayout
@using System.Text.Json
@using AliasVault.Client.Auth.Components
+@using AliasVault.Client.Auth.Models
@using AliasVault.Client.Utilities
@using AliasVault.Shared.Models.WebApi.Auth
@using AliasVault.Cryptography.Client
diff --git a/apps/server/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor b/apps/server/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
index 18236f87a..abe7232b1 100644
--- a/apps/server/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Widgets/CreateNewIdentityWidget.razor
@@ -1,5 +1,6 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.Extensions.Localization
+@using AliasVault.Client.Resources
@inherits AliasVault.Client.Main.Pages.MainBase
@inject IJSRuntime JSRuntime
@inject CredentialService CredentialService
@@ -234,7 +235,7 @@
/// <summary>
/// The service name.
/// </summary>
- [Required]
+ [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = nameof(ValidationMessages.ServiceNameRequired))]
[Display(Name = "Service Name")]
public string ServiceName { get; set; } = string.Empty;
diff --git a/apps/server/AliasVault.Client/Resources/Components/Auth/Login.en.resx b/apps/server/AliasVault.Client/Resources/Components/Auth/Login.en.resx
index 23d5e7d16..f8c7a22b6 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Auth/Login.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Auth/Login.en.resx
@@ -58,7 +58,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
-
+
<!-- Page titles -->
<data name="PageTitle" xml:space="preserve">
<value>Log in to AliasVault</value>
@@ -72,7 +72,7 @@
<value>Recovery code verification</value>
<comment>Title for recovery code step</comment>
</data>
-
+
<!-- Form labels -->
<data name="UsernameOrEmailLabel" xml:space="preserve">
<value>Your username or email</value>
@@ -98,7 +98,7 @@
<value>Remember this machine</value>
<comment>Label for remember machine checkbox</comment>
</data>
-
+
<!-- Buttons -->
<data name="LoginButton" xml:space="preserve">
<value>Log in</value>
@@ -108,7 +108,7 @@
<value>Login to your account</value>
<comment>Extended login button text</comment>
</data>
-
+
<!-- Links -->
<data name="LostPasswordLink" xml:space="preserve">
<value>Lost Password?</value>
@@ -119,14 +119,14 @@
<comment>Link text for creating a new vault</comment>
</data>
<data name="LoginWithRecoveryCodeLink" xml:space="preserve">
- <value>log in with a recovery code</value>
+ <value>Log in with a recovery code instead.</value>
<comment>Link text for logging in with recovery code</comment>
</data>
<data name="LoginWithAuthenticatorLink" xml:space="preserve">
- <value>log in with authenticator code</value>
+ <value>Log in with an authenticator code instead.</value>
<comment>Link text for logging in with authenticator</comment>
</data>
-
+
<!-- Descriptions and help text -->
<data name="TwoFactorAuthenticationDescription" xml:space="preserve">
<value>Your login is protected with an authenticator app. Enter your authenticator code below.</value>
@@ -141,14 +141,14 @@
<comment>Text before registration link</comment>
</data>
<data name="DontHaveAuthenticatorText" xml:space="preserve">
- <value>Don't have access to your authenticator device? You can</value>
- <comment>Text before recovery code link</comment>
+ <value>Don't have access to your authenticator device?</value>
+ <comment>Question text about not having access to authenticator</comment>
</data>
<data name="RegainedAccessText" xml:space="preserve">
- <value>Regained access to your authenticator device? You can</value>
- <comment>Text before authenticator login link</comment>
+ <value>Regained access to your authenticator device?</value>
+ <comment>Question text about regaining access to authenticator</comment>
</data>
-
+
<!-- Loading and status messages -->
<data name="LoggingInMessage" xml:space="preserve">
<value>Logging in...</value>
@@ -162,7 +162,7 @@
<value>Verifying recovery code...</value>
<comment>Loading message during recovery code verification</comment>
</data>
-
+
<!-- Error messages -->
<data name="LoginErrorMessage" xml:space="preserve">
<value>An error occurred while processing the login request. Try again (later).</value>
@@ -172,7 +172,7 @@
<value>An error occurred while processing the login request.</value>
<comment>Login request processing error message</comment>
</data>
-
+
<!-- Placeholders -->
<data name="UsernamePlaceholder" xml:space="preserve">
<value>name / [email protected]</value>
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index a89f11fe1..7ff27dfbd 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -2431,11 +2431,6 @@ video {
background-color: rgb(251 203 116 / var(--tw-bg-opacity));
}
-.hover\:bg-primary-400:hover {
- --tw-bg-opacity: 1;
- background-color: rgb(246 167 82 / var(--tw-bg-opacity));
-}
-
.hover\:bg-primary-600:hover {
--tw-bg-opacity: 1;
background-color: rgb(214 131 56 / var(--tw-bg-opacity));
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel.cs
deleted file mode 100644
index 643aa2fe6..000000000
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/LoginModel.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="LoginModel.cs" company="lanedirt">
-// Copyright (c) lanedirt. All rights reserved.
-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace AliasVault.Shared.Models.WebApi.Auth;
-
-using System.ComponentModel.DataAnnotations;
-
-/// <summary>
-/// Login model.
-/// </summary>
-public class LoginModel
-{
- /// <summary>
- /// Gets or sets the username.
- /// </summary>
- [Required]
- public string Username { get; set; } = null!;
-
- /// <summary>
- /// Gets or sets the password.
- /// </summary>
- [Required]
- public string Password { get; set; } = null!;
-
- /// <summary>
- /// Gets or sets a value indicating whether the user wants to be remembered.
- /// </summary>
- public bool RememberMe { get; set; } = true;
-}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/RegisterModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/RegisterModel.cs
deleted file mode 100644
index 253e5f7de..000000000
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/Auth/RegisterModel.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="RegisterModel.cs" company="lanedirt">
-// Copyright (c) lanedirt. All rights reserved.
-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace AliasVault.Shared.Models.WebApi.Auth;
-
-/// <summary>
-/// Register model.
-/// </summary>
-public class RegisterModel
-{
- /// <summary>
- /// Gets or sets the username.
- /// </summary>
- public string Username { get; set; } = null!;
-
- /// <summary>
- /// Gets or sets the password.
- /// </summary>
- public string Password { get; set; } = null!;
-
- /// <summary>
- /// Gets or sets the password confirmation.
- /// </summary>
- public string PasswordConfirm { get; set; } = null!;
-
- /// <summary>
- /// Gets or sets a value indicating whether the terms and conditions are accepted or not.
- /// </summary>
- public bool AcceptTerms { get; set; } = false;
-}