-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
28 changed files
with
208 additions
and
191 deletions.
There are no files selected for viewing
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
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
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
4 changes: 1 addition & 3 deletions
4
src/Server/Logistics.IdentityServer/Pages/Account/LoginWith2fa/Index.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
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
1 change: 1 addition & 0 deletions
1
src/Server/Logistics.IdentityServer/Pages/Account/Manage/ChangeAccount/Index.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
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
80 changes: 40 additions & 40 deletions
80
src/Server/Logistics.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,58 +1,58 @@ | ||
using Logistics.Domain.Entities; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace Logistics.IdentityServer.Pages.Account.Manage | ||
namespace Logistics.IdentityServer.Pages.Account.Manage; | ||
|
||
public class Disable2faModel : PageModel | ||
{ | ||
public class Disable2faModel : PageModel | ||
private readonly UserManager<User> _userManager; | ||
private readonly ILogger<Disable2faModel> _logger; | ||
|
||
public Disable2faModel( | ||
UserManager<User> userManager, | ||
ILogger<Disable2faModel> logger) | ||
{ | ||
private readonly UserManager<User> _userManager; | ||
private readonly ILogger<Disable2faModel> _logger; | ||
_userManager = userManager; | ||
_logger = logger; | ||
} | ||
|
||
public Disable2faModel( | ||
UserManager<User> userManager, | ||
ILogger<Disable2faModel> logger) | ||
[TempData] | ||
public string StatusMessage { get; set; } | ||
|
||
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)}'."); | ||
} | ||
|
||
[TempData] | ||
public string StatusMessage { get; set; } | ||
if (!await _userManager.GetTwoFactorEnabledAsync(user)) | ||
{ | ||
throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled."); | ||
} | ||
|
||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnGet() | ||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
var user = await _userManager.GetUserAsync(User); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); | ||
} | ||
|
||
if (!await _userManager.GetTwoFactorEnabledAsync(user)) | ||
{ | ||
throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled."); | ||
} | ||
|
||
return Page(); | ||
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 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"); | ||
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"); | ||
} | ||
} |
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
Oops, something went wrong.