diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml b/src/UI/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml index 28bc1c5add..e2126672e2 100644 --- a/src/UI/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml +++ b/src/UI/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml @@ -5,6 +5,7 @@ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication; } +@Html.Partial("_StatusMessage", Model.StatusMessage)
To use an authenticator app go through the following steps:
diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs b/src/UI/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs index 51ceaa5491..1f64a0ac51 100644 --- a/src/UI/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs +++ b/src/UI/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; @@ -38,6 +37,9 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage [TempData] public string[] RecoveryCodes { get; set; } + [TempData] + public string StatusMessage { get; set; } + [BindProperty] public InputModel Input { get; set; } @@ -93,9 +95,18 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage await _userManager.SetTwoFactorEnabledAsync(user, true); _logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", user.Id); - var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); - RecoveryCodes = recoveryCodes.ToArray(); - return RedirectToPage("./ShowRecoveryCodes"); + StatusMessage = "Your authenticator app has been verified."; + + if (await _userManager.CountRecoveryCodesAsync(user) == 0) + { + var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); + RecoveryCodes = recoveryCodes.ToArray(); + return RedirectToPage("./ShowRecoveryCodes"); + } + else + { + return RedirectToPage("./TwoFactorAuthentication"); + } } private async Task LoadSharedKeyAndQrCodeUriAsync(IdentityUser user) diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml b/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml index d6a39d1937..ffc8d678ef 100644 --- a/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml +++ b/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml @@ -5,6 +5,7 @@ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication; } +@Html.Partial("_StatusMessage", Model.StatusMessage)
diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs b/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
index 4ff6551ca0..02ad485961 100644
--- a/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
+++ b/src/UI/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
@@ -26,6 +26,9 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage
[TempData]
public string[] RecoveryCodes { get; set; }
+ [TempData]
+ public string StatusMessage { get; set; }
+
public async Task
@@ -12,7 +13,7 @@
If you reset your authenticator key your authenticator app will not work until you reconfigure it.
- This process disables 2FA until you verify your authenticator app and will also reset your 2FA recovery codes.
+ 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.
diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml.cs b/src/UI/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml.cs
index c865922898..ca29098c68 100644
--- a/src/UI/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml.cs
+++ b/src/UI/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml.cs
@@ -1,12 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-using System;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
-using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage
{
@@ -15,6 +11,9 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage
[TempData]
public string[] RecoveryCodes { get; set; }
+ [TempData]
+ public string StatusMessage { get; set; }
+
public IActionResult OnGet()
{
if (RecoveryCodes == null || RecoveryCodes.Length == 0)
diff --git a/src/UI/Areas/Identity/Pages/Account/Manage/TwoFactorAuthentication.cshtml b/src/UI/Areas/Identity/Pages/Account/Manage/TwoFactorAuthentication.cshtml
index 19ba8daacb..f4e47924fa 100644
--- a/src/UI/Areas/Identity/Pages/Account/Manage/TwoFactorAuthentication.cshtml
+++ b/src/UI/Areas/Identity/Pages/Account/Manage/TwoFactorAuthentication.cshtml
@@ -4,6 +4,7 @@
ViewData["Title"] = "Two-factor authentication (2FA)";
}
+@Html.Partial("_StatusMessage", Model.StatusMessage)
@ViewData["Title"]
@ViewData["Title"]
@ViewData["Title"]
@if (Model.Is2faEnabled)
{
@@ -29,6 +30,12 @@