2024-05-02 07:43:47 +01:00
@page "/Account/Manage/ResetAuthenticator"
2024-05-03 03:24:40 +01:00
@using Microsoft.AspNetCore.Identity
2024-05-02 07:43:47 +01:00
2024-05-03 22:54:50 +01:00
@inject UserManager<IdentityUser> UserManager
@inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager
@inject ILogger<ResetAuthenticator> Logger
2024-05-02 07:43:47 +01:00
<PageTitle>Reset authenticator key</PageTitle>
<StatusMessage/>
<h3>Reset authenticator key</h3>
<div class="alert alert-warning" role="alert">
<p>
<span class="glyphicon glyphicon-warning-sign"></span>
<strong>If you reset your authenticator key your authenticator app will not work until you reconfigure it.</strong>
</p>
<p>
This process disables 2FA until you verify your authenticator app.
If you do not complete your authenticator app configuration you may lose access to your account.
</p>
</div>
<div>
<form @formname="reset-authenticator" method="post" @onsubmit="OnSubmitAsync">
<AntiforgeryToken/>
<button class="btn btn-danger" type="submit">Reset authenticator key</button>
</form>
</div>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private async Task OnSubmitAsync()
{
2024-05-03 22:54:50 +01:00
IdentityUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
2024-05-02 07:43:47 +01:00
await UserManager.SetTwoFactorEnabledAsync(user, false);
await UserManager.ResetAuthenticatorKeyAsync(user);
2024-05-03 03:24:40 +01:00
string userId = await UserManager.GetUserIdAsync(user);
2024-05-02 07:43:47 +01:00
Logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", userId);
await SignInManager.RefreshSignInAsync(user);
RedirectManager.RedirectToWithStatus("Account/Manage/EnableAuthenticator", "Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.", HttpContext);
}
}