From 2097b1d919c5be80623693fe9f5ce134d7567b3b Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Sun, 21 Jan 2024 18:33:32 +0100 Subject: [PATCH] Improved LoginWith2fa --- .../Account/Pages/LoginWith2fa.razor | 90 ++++++------- .../Account/Pages/LoginWith2fa.de-DE.resx | 122 +++++++++++++++++ .../Account/Pages/LoginWith2fa.en-GB.resx | 101 ++++++++++++++ .../Account/Pages/LoginWith2fa.resx | 125 ++++++++++++++++++ 4 files changed, 388 insertions(+), 50 deletions(-) create mode 100644 Wave/Resources/Components/Account/Pages/LoginWith2fa.de-DE.resx create mode 100644 Wave/Resources/Components/Account/Pages/LoginWith2fa.en-GB.resx create mode 100644 Wave/Resources/Components/Account/Pages/LoginWith2fa.resx diff --git a/Wave/Components/Account/Pages/LoginWith2fa.razor b/Wave/Components/Account/Pages/LoginWith2fa.razor index ce563c7..9ab9833 100644 --- a/Wave/Components/Account/Pages/LoginWith2fa.razor +++ b/Wave/Components/Account/Pages/LoginWith2fa.razor @@ -8,87 +8,77 @@ @inject UserManager UserManager @inject IdentityRedirectManager RedirectManager @inject ILogger Logger +@inject IStringLocalizer Localizer -Two-factor authentication +@Localizer["Title"] -

Two-factor authentication

-
- -

Your login is protected with an authenticator app. Enter your authenticator code below.

-
-
+ + + + +

@Localizer["Message"]

- -
- - - -
-
-
-
-

- Don't have access to your authenticator device? You can - log in with a recovery code. -

+

+ + @Localizer["RecoveryCodes_Label"] + +

+ + + @code { - private string? message; - private ApplicationUser user = default!; - + [SupplyParameterFromQuery] + private bool RememberMe { get; set; } [SupplyParameterFromForm] private InputModel Input { get; set; } = new(); - [SupplyParameterFromQuery] private string? ReturnUrl { get; set; } - [SupplyParameterFromQuery] - private bool RememberMe { get; set; } + private string? Message { get; set; } + private ApplicationUser User { get; set; } = default!; - protected override async Task OnInitializedAsync() - { + protected override async Task OnInitializedAsync() { // Ensure the user has gone through the username & password screen first - user = await SignInManager.GetTwoFactorAuthenticationUserAsync() ?? + User = await SignInManager.GetTwoFactorAuthenticationUserAsync() ?? throw new InvalidOperationException("Unable to load two-factor authentication user."); } - private async Task OnValidSubmitAsync() - { - var authenticatorCode = Input.TwoFactorCode!.Replace(" ", string.Empty).Replace("-", string.Empty); + private async Task OnValidSubmitAsync() { + string authenticatorCode = Input.TwoFactorCode!.Replace(" ", string.Empty).Replace("-", string.Empty); var result = await SignInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, RememberMe, Input.RememberMachine); - var userId = await UserManager.GetUserIdAsync(user); + string userId = await UserManager.GetUserIdAsync(User); - if (result.Succeeded) - { + if (result.Succeeded) { Logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", userId); RedirectManager.RedirectTo(ReturnUrl); - } - else if (result.IsLockedOut) - { + } else if (result.IsLockedOut) { Logger.LogWarning("User with ID '{UserId}' account locked out.", userId); RedirectManager.RedirectTo("Account/Lockout"); - } - else - { + } else { Logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", userId); - message = "Error: Invalid authenticator code."; + Message = Localizer["TwoFactorCode_ErrorInvalidCode"]; } } - private sealed class InputModel - { + private sealed class InputModel { [Required] [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] [DataType(DataType.Text)] diff --git a/Wave/Resources/Components/Account/Pages/LoginWith2fa.de-DE.resx b/Wave/Resources/Components/Account/Pages/LoginWith2fa.de-DE.resx new file mode 100644 index 0000000..a3057fa --- /dev/null +++ b/Wave/Resources/Components/Account/Pages/LoginWith2fa.de-DE.resx @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Anmelden + + + Computer Merken + + + Zwei Faktor Authentifizierung + + + 2fa Schlüssel + + + Kein Zugriff auf Ihre 2fa app? Melden Sie sich mit einem Wiederherstellungsschlüssel an. + + + Ihr Benutzerkonto ist mit einer Authentifizierungsapp geschützt. Geben Sie ihren 2fa Schlüssel unten ein. + + + Fehler: Inkorrekter Schlüssel + + \ No newline at end of file diff --git a/Wave/Resources/Components/Account/Pages/LoginWith2fa.en-GB.resx b/Wave/Resources/Components/Account/Pages/LoginWith2fa.en-GB.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Wave/Resources/Components/Account/Pages/LoginWith2fa.en-GB.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Wave/Resources/Components/Account/Pages/LoginWith2fa.resx b/Wave/Resources/Components/Account/Pages/LoginWith2fa.resx new file mode 100644 index 0000000..4332d8e --- /dev/null +++ b/Wave/Resources/Components/Account/Pages/LoginWith2fa.resx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Two-factor authentication + + + 2FA Code + + + xxx xxx + + + Remember Computer + + + Log In + + + Don't have access to your authenticator device? You can log in with a recovery code. + + + Your login is protected with an authenticator app. Enter your authenticator code below. + + + Error: Invalid authenticator code. + + \ No newline at end of file