public async Task <IActionResult> Disable2fa() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound(_sharedLocalizer["USER_NOTFOUND", _userManager.GetUserId(User)])); } // remove Fido2 MFA if it exists await _fido2Storage.RemoveCredentialsByUsername(user.UserName); var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); if (!disable2faResult.Succeeded) { throw new ApplicationException($"Unexpected error occured disabling 2FA for user with ID '{user.Id}'."); } _logger.LogInformation("User with ID {UserId} has disabled 2fa.", user.Id); return(RedirectToAction(nameof(TwoFactorAuthentication))); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } await _fido2Storage.RemoveCredentialsByUsername(user.UserName); var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); if (!disable2faResult.Succeeded) { throw new InvalidOperationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'."); } _logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User)); StatusMessage = "2fa has been disabled. You can reenable 2fa when you setup an authenticator app"; return(RedirectToPage("./TwoFactorAuthentication")); }