-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b869bbd
commit 75e376c
Showing
26 changed files
with
1,027 additions
and
1,286 deletions.
There are no files selected for viewing
9 changes: 4 additions & 5 deletions
9
AspireForIdentityServer.IdentityServer/Pages/Account/AccessDenied.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace IdentityServer.Pages.Account | ||
namespace IdentityServer.Pages.Account; | ||
|
||
public class AccessDeniedModel : PageModel | ||
{ | ||
public class AccessDeniedModel : PageModel | ||
public void OnGet() | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 38 additions & 48 deletions
86
AspireForIdentityServer.IdentityServer/Pages/Account/Manage/Disable2fa.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
#nullable disable | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using IdentityServer.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IdentityServer.Areas.Identity.Pages.Account.Manage | ||
namespace IdentityServer.Areas.Identity.Pages.Account.Manage; | ||
|
||
public class Disable2faModel : PageModel | ||
{ | ||
public class Disable2faModel : PageModel | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly ILogger<Disable2faModel> _logger; | ||
|
||
public Disable2faModel( | ||
UserManager<ApplicationUser> userManager, | ||
ILogger<Disable2faModel> logger) | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly ILogger<Disable2faModel> _logger; | ||
_userManager = userManager; | ||
_logger = logger; | ||
} | ||
|
||
[TempData] | ||
public string StatusMessage { get; set; } | ||
|
||
public Disable2faModel( | ||
UserManager<ApplicationUser> userManager, | ||
ILogger<Disable2faModel> logger) | ||
public async Task<IActionResult> OnGet() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
_userManager = userManager; | ||
_logger = logger; | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[TempData] | ||
public string StatusMessage { get; set; } | ||
|
||
public async Task<IActionResult> OnGet() | ||
if (!await _userManager.GetTwoFactorEnabledAsync(user)) | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
throw new InvalidOperationException($"Cannot disable 2FA for user as it's not currently enabled."); | ||
} | ||
|
||
if (!await _userManager.GetTwoFactorEnabledAsync(user)) | ||
{ | ||
throw new InvalidOperationException($"Cannot disable 2FA for user as it's not currently enabled."); | ||
} | ||
return Page(); | ||
} | ||
|
||
return Page(); | ||
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)}'."); | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); | ||
if (!disable2faResult.Succeeded) | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); | ||
if (!disable2faResult.Succeeded) | ||
{ | ||
throw new InvalidOperationException($"Unexpected error occurred disabling 2FA."); | ||
} | ||
|
||
_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"); | ||
throw new InvalidOperationException($"Unexpected error occurred disabling 2FA."); | ||
} | ||
|
||
_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"); | ||
} | ||
} |
Oops, something went wrong.