Skip to content

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

Add ApiErrors enum translations and implement to client login (#1006)

Leendert de Borst8213a8132114
diff --git a/apps/server/AliasVault.Client/Auth/Pages/Login.razor b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
index 0daf9736b..4639d58cd 100644
--- a/apps/server/AliasVault.Client/Auth/Pages/Login.razor
+++ b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
@@ -127,6 +127,7 @@ else
private bool _showLoginWithRecoveryCodeStep;
private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Auth.Login", "AliasVault.Client");
+ private IStringLocalizer ApiErrorLocalizer => LocalizerFactory.Create("ApiErrors", "AliasVault.Client");
private SrpEphemeral _clientEphemeral = new();
private SrpSession _clientSession = new();
@@ -224,7 +225,7 @@ else
if (!result.IsSuccessStatusCode)
{
- return ApiResponseUtility.ParseErrorResponse(responseContent);
+ return ApiResponseUtility.ParseErrorResponse(responseContent, ApiErrorLocalizer);
}
var loginResponse = JsonSerializer.Deserialize<LoginInitiateResponse>(responseContent);
@@ -255,7 +256,7 @@ else
if (!result.IsSuccessStatusCode)
{
- return ApiResponseUtility.ParseErrorResponse(responseContent);
+ return ApiResponseUtility.ParseErrorResponse(responseContent, ApiErrorLocalizer);
}
var validateLoginResponse = JsonSerializer.Deserialize<ValidateLoginResponse>(responseContent);
@@ -297,7 +298,7 @@ else
if (!result.IsSuccessStatusCode)
{
- foreach (var error in ApiResponseUtility.ParseErrorResponse(responseContent))
+ foreach (var error in ApiResponseUtility.ParseErrorResponse(responseContent, ApiErrorLocalizer))
{
_serverValidationErrors.AddError(error);
}
@@ -355,7 +356,7 @@ else
if (!result.IsSuccessStatusCode)
{
- foreach (var error in ApiResponseUtility.ParseErrorResponse(responseContent))
+ foreach (var error in ApiResponseUtility.ParseErrorResponse(responseContent, ApiErrorLocalizer))
{
_serverValidationErrors.AddError(error);
}
diff --git a/apps/server/AliasVault.Client/Resources/ApiErrors.en.resx b/apps/server/AliasVault.Client/Resources/ApiErrors.en.resx
new file mode 100644
index 000000000..ad752d5f3
--- /dev/null
+++ b/apps/server/AliasVault.Client/Resources/ApiErrors.en.resx
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="REFRESH_TOKEN_REQUIRED" xml:space="preserve">
+ <value>Refresh token is required.</value>
+ </data>
+ <data name="USER_NOT_FOUND_IN_TOKEN" xml:space="preserve">
+ <value>User not found (name-1)</value>
+ </data>
+ <data name="USER_NOT_FOUND_IN_DATABASE" xml:space="preserve">
+ <value>User not found (name-2)</value>
+ </data>
+ <data name="ACCOUNT_BLOCKED" xml:space="preserve">
+ <value>Your account has been disabled. If you believe this is a mistake, please contact support.</value>
+ </data>
+ <data name="INVALID_REFRESH_TOKEN" xml:space="preserve">
+ <value>Invalid refresh token</value>
+ </data>
+ <data name="REFRESH_TOKEN_REVOKED_SUCCESSFULLY" xml:space="preserve">
+ <value>Refresh token revoked successfully</value>
+ </data>
+ <data name="PUBLIC_REGISTRATION_DISABLED" xml:space="preserve">
+ <value>New account registration is currently disabled on this server. Please contact the administrator.</value>
+ </data>
+ <data name="USER_NOT_FOUND" xml:space="preserve">
+ <value>Invalid username or password. Please try again.</value>
+ </data>
+ <data name="USERNAME_REQUIRED" xml:space="preserve">
+ <value>Username is required.</value>
+ </data>
+ <data name="USERNAME_ALREADY_IN_USE" xml:space="preserve">
+ <value>Username is already in use.</value>
+ </data>
+ <data name="USERNAME_AVAILABLE" xml:space="preserve">
+ <value>Username is available.</value>
+ </data>
+ <data name="USERNAME_MISMATCH" xml:space="preserve">
+ <value>Username does not match the current user.</value>
+ </data>
+ <data name="PASSWORD_MISMATCH" xml:space="preserve">
+ <value>The provided password does not match your current password.</value>
+ </data>
+ <data name="ACCOUNT_SUCCESSFULLY_DELETED" xml:space="preserve">
+ <value>Account successfully deleted.</value>
+ </data>
+ <data name="USERNAME_EMPTY_OR_WHITESPACE" xml:space="preserve">
+ <value>Username cannot be empty or whitespace.</value>
+ </data>
+ <data name="USERNAME_TOO_SHORT" xml:space="preserve">
+ <value>Username too short: must be at least 3 characters long.</value>
+ </data>
+ <data name="USERNAME_TOO_LONG" xml:space="preserve">
+ <value>Username too long: cannot be longer than 40 characters.</value>
+ </data>
+ <data name="USERNAME_ADMIN_NOT_ALLOWED" xml:space="preserve">
+ <value>Username 'admin' is not allowed.</value>
+ </data>
+ <data name="USERNAME_INVALID_EMAIL" xml:space="preserve">
+ <value>Invalid email address.</value>
+ </data>
+ <data name="USERNAME_INVALID_CHARACTERS" xml:space="preserve">
+ <value>Username is invalid, can only contain letters or digits.</value>
+ </data>
+ <data name="PENDING_MIGRATIONS" xml:space="preserve">
+ <value>There are pending migrations. Please run 'dotnet ef database update' to apply them.</value>
+ </data>
+ <data name="SYSTEM_OK" xml:space="preserve">
+ <value>OK</value>
+ </data>
+ <data name="INTERNAL_SERVER_ERROR" xml:space="preserve">
+ <value>Internal server error</value>
+ </data>
+ <data name="VAULT_ERROR" xml:space="preserve">
+ <value>The local vault is not up-to-date. Please synchronize your vault by refreshing the page and try again.</value>
+ </data>
+ <data name="UNKNOWN_ERROR" xml:space="preserve">
+ <value>An unknown error occurred. Please try again.</value>
+ </data>
+ <data name="INVALID_AUTHENTICATOR_CODE" xml:space="preserve">
+ <value>Invalid authenticator code. Please try again.</value>
+ </data>
+ <data name="INVALID_RECOVERY_CODE" xml:space="preserve">
+ <value>Invalid recovery code. Please try again.</value>
+ </data>
+ <data name="VAULT_NOT_UP_TO_DATE" xml:space="preserve">
+ <value>Your vault is not up-to-date. Please synchronize your vault and try again.</value>
+ </data>
+ <data name="ACCOUNT_LOCKED" xml:space="preserve">
+ <value>You have entered an incorrect password too many times and your account has now been locked out. You can try again in 30 minutes.</value>
+ </data>
+</root>