Reformat new server project.

This commit is contained in:
2024-05-03 03:24:40 +01:00
parent a85ca9efc6
commit be385713c2
46 changed files with 419 additions and 458 deletions

View File

@@ -1,11 +1,10 @@
@page "/Account/Manage/EnableAuthenticator"
@using System.ComponentModel.DataAnnotations
@using System.Globalization
@using System.Text
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager
@inject IdentityUserAccessor UserAccessor
@@ -22,6 +21,7 @@
else
{
<StatusMessage Message="@message"/>
<h3>Configure authenticator app</h3>
<div>
<p>To use an authenticator app go through the following steps:</p>
@@ -91,9 +91,9 @@ else
private async Task OnValidSubmitAsync()
{
// Strip spaces and hyphens
var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
string verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
var is2faTokenValid = await UserManager.VerifyTwoFactorTokenAsync(user, UserManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);
bool is2faTokenValid = await UserManager.VerifyTwoFactorTokenAsync(user, UserManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);
if(!is2faTokenValid)
{
@@ -103,7 +103,7 @@ else
}
await UserManager.SetTwoFactorEnabledAsync(user, true);
var userId = await UserManager.GetUserIdAsync(user);
string userId = await UserManager.GetUserIdAsync(user);
Logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);
message = "Your authenticator app has been verified.";
@@ -121,7 +121,7 @@ else
private async ValueTask LoadSharedKeyAndQrCodeUriAsync(ApplicationUser user)
{
// Load the authenticator key & QR code URI to display on the form
var unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user);
string? unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user);
if(string.IsNullOrEmpty(unformattedKey))
{
@@ -131,14 +131,14 @@ else
sharedKey = FormatKey(unformattedKey!);
var email = await UserManager.GetEmailAsync(user);
string? email = await UserManager.GetEmailAsync(user);
authenticatorUri = GenerateQrCodeUri(email!, unformattedKey!);
}
private string FormatKey(string unformattedKey)
{
var result = new StringBuilder();
int currentPosition = 0;
var currentPosition = 0;
while(currentPosition + 4 < unformattedKey.Length)
{
@@ -154,10 +154,7 @@ else
return result.ToString().ToLowerInvariant();
}
private string GenerateQrCodeUri(string email, string unformattedKey)
{
return string.Format(CultureInfo.InvariantCulture, AuthenticatorUriFormat, UrlEncoder.Encode("Microsoft.AspNetCore.Identity.UI"), UrlEncoder.Encode(email), unformattedKey);
}
private string GenerateQrCodeUri(string email, string unformattedKey) => string.Format(CultureInfo.InvariantCulture, AuthenticatorUriFormat, UrlEncoder.Encode("Microsoft.AspNetCore.Identity.UI"), UrlEncoder.Encode(email), unformattedKey);
private sealed class InputModel
{