mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-01-02 11:09:42 -05:00
Merge pull request #278 from lanedirt/275-make-2fa-input-field-number-input
Make 2fa input field a number
This commit is contained in:
@@ -168,7 +168,7 @@ public class AuthController(IDbContextFactory<AliasServerDbContext> dbContextFac
|
||||
}
|
||||
|
||||
// Verify 2-factor code.
|
||||
var verifyResult = await userManager.VerifyTwoFactorTokenAsync(user, userManager.Options.Tokens.AuthenticatorTokenProvider, model.Code2Fa);
|
||||
var verifyResult = await userManager.VerifyTwoFactorTokenAsync(user, userManager.Options.Tokens.AuthenticatorTokenProvider, model.Code2Fa.ToString());
|
||||
if (!verifyResult)
|
||||
{
|
||||
// Increment failed login attempts in order to lock out the account when the limit is reached.
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
<div class="w-full">
|
||||
<EditForm Model="LoginModel2Fa" FormName="login-with-2fa" OnValidSubmit="Handle2Fa" method="post" class="space-y-6">
|
||||
<DataAnnotationsValidator/>
|
||||
<ValidationSummary class="text-red-600 dark:text-red-400" role="alert"/>
|
||||
<div>
|
||||
<label for="two-factor-code" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Authenticator code</label>
|
||||
<InputText @bind-Value="LoginModel2Fa.TwoFactorCode" id="two-factor-code" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" autocomplete="off"/>
|
||||
<InputNumber @bind-Value="LoginModel2Fa.TwoFactorCode" id="two-factor-code" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" autocomplete="off"/>
|
||||
<ValidationMessage For="() => LoginModel2Fa.TwoFactorCode" class="text-red-600 dark:text-red-400 text-sm mt-1"/>
|
||||
</div>
|
||||
<div class="flex items-start">
|
||||
@@ -58,7 +57,6 @@ else if (ShowLoginWithRecoveryCodeStep)
|
||||
<div class="w-full">
|
||||
<EditForm Model="LoginModelRecoveryCode" FormName="login-with-recovery-code" OnValidSubmit="HandleRecoveryCode" method="post" class="space-y-6">
|
||||
<DataAnnotationsValidator/>
|
||||
<ValidationSummary class="text-red-600 dark:text-red-400" role="alert"/>
|
||||
<div>
|
||||
<label for="two-factor-code" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Recovery Code</label>
|
||||
<InputText @bind-Value="LoginModelRecoveryCode.RecoveryCode" id="recovery-code" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" autocomplete="off"/>
|
||||
@@ -328,7 +326,7 @@ else
|
||||
var username = LoginModel.Username.ToLowerInvariant().Trim();
|
||||
|
||||
// Validate 2-factor auth code auth and login
|
||||
var result = await Http.PostAsJsonAsync("api/v1/Auth/validate-2fa", new ValidateLoginRequest2Fa(username, LoginModel.RememberMe, ClientEphemeral.Public, ClientSession.Proof, LoginModel2Fa.TwoFactorCode));
|
||||
var result = await Http.PostAsJsonAsync("api/v1/Auth/validate-2fa", new ValidateLoginRequest2Fa(username, LoginModel.RememberMe, ClientEphemeral.Public, ClientSession.Proof, LoginModel2Fa.TwoFactorCode ?? 0));
|
||||
var responseContent = await result.Content.ReadAsStringAsync();
|
||||
|
||||
if (!result.IsSuccessStatusCode)
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
/// The notes to display.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Notes { get; set; } = "";
|
||||
|
||||
private static string ConvertUrlsToLinks(string text)
|
||||
{
|
||||
string urlPattern = @"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})";
|
||||
return Regex.Replace(text, urlPattern, match => $"<a href=\"{match.Value}\" target=\"_blank\" class=\"text-blue-500 hover:underline\">{match.Value}</a>", RegexOptions.NonBacktracking);
|
||||
return Regex.Replace(text, urlPattern, match => $"<a href=\"{match.Value}\" target=\"_blank\" class=\"text-blue-500 hover:underline\">{match.Value}</a>", RegexOptions.None, TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,16 @@ namespace AliasVault.Shared.Models.WebApi.Auth;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// Login model for two factor authentication step using an authenticator code.
|
||||
/// Login model for 2-factor authentication step using an authenticator code.
|
||||
/// </summary>
|
||||
public class LoginModel2Fa
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the two factor code.
|
||||
/// Gets or sets the 2-factor code.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string TwoFactorCode { get; set; } = null!;
|
||||
[Display(Name = "Authenticator Code")]
|
||||
public int? TwoFactorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the current machine should not be asked for 2FA the next time.
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace AliasVault.Shared.Models.WebApi.Auth
|
||||
/// <param name="clientPublicEphemeral">Client public ephemeral.</param>
|
||||
/// <param name="clientSessionProof">Client session proof.</param>
|
||||
/// <param name="code2Fa">2-factor authentication code.</param>
|
||||
public ValidateLoginRequest2Fa(string username, bool rememberMe, string clientPublicEphemeral, string clientSessionProof, string code2Fa)
|
||||
public ValidateLoginRequest2Fa(string username, bool rememberMe, string clientPublicEphemeral, string clientSessionProof, int code2Fa)
|
||||
: base(username, rememberMe, clientPublicEphemeral, clientSessionProof)
|
||||
{
|
||||
Code2Fa = code2Fa;
|
||||
@@ -29,6 +29,6 @@ namespace AliasVault.Shared.Models.WebApi.Auth
|
||||
/// <summary>
|
||||
/// Gets the 2-factor authentication code.
|
||||
/// </summary>
|
||||
public string Code2Fa { get; }
|
||||
public int Code2Fa { get; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user