Localize Enable2Fa page (#1006)

This commit is contained in:
Leendert de Borst
2025-07-14 18:07:30 +02:00
committed by Leendert de Borst
parent 3c36020812
commit f4c4962cb8
2 changed files with 120 additions and 11 deletions

View File

@@ -1,15 +1,16 @@
@page "/settings/security/enable-2fa"
@using AliasVault.Client.Main.Pages.Settings.Security.Components
@using Microsoft.Extensions.Localization
@inherits MainBase
@inject HttpClient Http
<LayoutPageTitle>Enable two-factor authentication</LayoutPageTitle>
<LayoutPageTitle>@Localizer["PageTitle"]</LayoutPageTitle>
<div class="grid grid-cols-1 px-4 pt-6 xl:grid-cols-3 xl:gap-4 dark:bg-gray-900">
<div class="mb-4 col-span-full xl:mb-2">
<Breadcrumb BreadcrumbItems="BreadcrumbItems"/>
<H1>Enable two-factor authentication</H1>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Enable two-factor authentication to increase the security of your vaults.</p>
<H1>@Localizer["PageTitle"]</H1>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">@Localizer["PageDescription"]</p>
</div>
</div>
@@ -30,7 +31,7 @@ else
</div>
<p class="text-sm text-gray-600 text-center">
Scan this QR code with your authenticator app or enter the following secret manually:
@Localizer["QrCodeInstructions"]
</p>
<div class="text-lg font-mono text-center bg-gray-100 p-2 rounded" id="authenticator-secret">@Secret</div>
@@ -38,11 +39,11 @@ else
<div>
<InputText id="verificationCode" @bind-Value="VerifyModel.Code"
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Enter verification code"/>
placeholder="@Localizer["VerificationCodePlaceholder"]"/>
</div>
<button type="submit"
class="w-full bg-primary-500 text-white py-2 px-4 rounded-md hover:bg-primary-600 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 transition duration-150 ease-in-out">
Verify and Enable
@Localizer["VerifyAndEnableButton"]
</button>
</EditForm>
</div>
@@ -56,13 +57,15 @@ else
private List<string>? RecoveryCodes { get; set; }
private readonly VerificationModel VerifyModel = new();
private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Pages.Settings.Security.Enable2Fa", "AliasVault.Client");
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = "Security settings", Url = "/settings/security" });
BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = "Enable two-factor authentication" });
BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = Localizer["BreadcrumbSecuritySettings"], Url = "/settings/security" });
BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = Localizer["BreadcrumbEnable2Fa"] });
}
/// <inheritdoc />
@@ -107,8 +110,7 @@ else
if (result != null)
{
GlobalNotificationService.AddSuccessMessage("Two-factor authentication is now successfully enabled. On your " +
"next login you will need to enter your 2FA code.", true);
GlobalNotificationService.AddSuccessMessage(Localizer["TwoFactorEnabledSuccess"], true);
// Show recovery codes.
RecoveryCodes = result.RecoveryCodes;
@@ -118,7 +120,7 @@ else
}
}
GlobalNotificationService.AddErrorMessage("Failed to enable two-factor authentication.", true);
GlobalNotificationService.AddErrorMessage(Localizer["FailedToEnable2Fa"], true);
StateHasChanged();
}

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<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" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</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" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
</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>
<!-- Page title and breadcrumbs -->
<data name="PageTitle" xml:space="preserve">
<value>Enable two-factor authentication</value>
<comment>Page title for the enable 2FA page</comment>
</data>
<data name="BreadcrumbSecuritySettings" xml:space="preserve">
<value>Security settings</value>
<comment>Breadcrumb text for security settings</comment>
</data>
<data name="BreadcrumbEnable2Fa" xml:space="preserve">
<value>Enable two-factor authentication</value>
<comment>Breadcrumb text for enable 2FA</comment>
</data>
<!-- Page description -->
<data name="PageDescription" xml:space="preserve">
<value>Enable two-factor authentication to increase the security of your vaults.</value>
<comment>Description text explaining 2FA setup</comment>
</data>
<!-- Setup instructions -->
<data name="QrCodeInstructions" xml:space="preserve">
<value>Scan this QR code with your authenticator app or enter the following secret manually:</value>
<comment>Instructions for scanning QR code or entering secret</comment>
</data>
<!-- Form elements -->
<data name="VerificationCodePlaceholder" xml:space="preserve">
<value>Enter verification code</value>
<comment>Placeholder text for verification code input</comment>
</data>
<data name="VerifyAndEnableButton" xml:space="preserve">
<value>Verify and Enable</value>
<comment>Button text to verify and enable 2FA</comment>
</data>
<!-- Success and error messages -->
<data name="TwoFactorEnabledSuccess" xml:space="preserve">
<value>Two-factor authentication is now successfully enabled. On your next login you will need to enter your 2FA code.</value>
<comment>Success message when 2FA is enabled</comment>
</data>
<data name="FailedToEnable2Fa" xml:space="preserve">
<value>Failed to enable two-factor authentication.</value>
<comment>Error message when 2FA setup fails</comment>
</data>
</root>