diff --git a/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs b/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
new file mode 100644
index 0000000..274af13
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ConfirmEmailModel : PageModel
+ {
+ private readonly UserManager _userManager;
+
+ public ConfirmEmailModel(UserManager userManager)
+ {
+ _userManager = userManager;
+ }
+
+ public async Task OnGetAsync(string userId, string code)
+ {
+ if (userId == null || code == null)
+ {
+ return RedirectToPage("/Index");
+ }
+
+ var user = await _userManager.FindByIdAsync(userId);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{userId}'.");
+ }
+
+ var result = await _userManager.ConfirmEmailAsync(user, code);
+ if (!result.Succeeded)
+ {
+ throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':");
+ }
+
+ return Page();
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/ExternalLogin.cshtml b/Areas/Identity/Pages/Account/ExternalLogin.cshtml
new file mode 100644
index 0000000..54273e2
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ExternalLogin.cshtml
@@ -0,0 +1,34 @@
+@page
+@model ExternalLoginModel
+@{
+ ViewData["Title"] = "Register";
+}
+
+
@ViewData["Title"]
+
Associate your @Model.LoginProvider account.
+
+
+
+ You've successfully authenticated with @Model.LoginProvider.
+ Please enter an email address for this site below and click the Register button to finish
+ logging in.
+
+
+
+
+
+
+
+
+@section Scripts {
+
+}
+
diff --git a/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs b/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs
new file mode 100644
index 0000000..9ce9d95
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Security.Claims;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ExternalLoginModel : PageModel
+ {
+ private readonly SignInManager _signInManager;
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+
+ public ExternalLoginModel(
+ SignInManager signInManager,
+ UserManager userManager,
+ ILogger logger)
+ {
+ _signInManager = signInManager;
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public string LoginProvider { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ [TempData]
+ public string ErrorMessage { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [EmailAddress]
+ public string Email { get; set; }
+ }
+
+ public IActionResult OnGetAsync()
+ {
+ return RedirectToPage("./Login");
+ }
+
+ public IActionResult OnPost(string provider, string returnUrl = null)
+ {
+ // Request a redirect to the external login provider.
+ var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
+ var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
+ return new ChallengeResult(provider, properties);
+ }
+
+ public async Task OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
+ {
+ returnUrl = returnUrl ?? Url.Content("~/");
+ if (remoteError != null)
+ {
+ ErrorMessage = $"Error from external provider: {remoteError}";
+ return RedirectToPage("./Login", new {ReturnUrl = returnUrl });
+ }
+ var info = await _signInManager.GetExternalLoginInfoAsync();
+ if (info == null)
+ {
+ ErrorMessage = "Error loading external login information.";
+ return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
+ }
+
+ // Sign in the user with this external login provider if the user already has a login.
+ var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor : true);
+ if (result.Succeeded)
+ {
+ _logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
+ return LocalRedirect(returnUrl);
+ }
+ if (result.IsLockedOut)
+ {
+ return RedirectToPage("./Lockout");
+ }
+ else
+ {
+ // If the user does not have an account, then ask the user to create an account.
+ ReturnUrl = returnUrl;
+ LoginProvider = info.LoginProvider;
+ if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
+ {
+ Input = new InputModel
+ {
+ Email = info.Principal.FindFirstValue(ClaimTypes.Email)
+ };
+ }
+ return Page();
+ }
+ }
+
+ public async Task OnPostConfirmationAsync(string returnUrl = null)
+ {
+ returnUrl = returnUrl ?? Url.Content("~/");
+ // Get the information about the user from the external login provider
+ var info = await _signInManager.GetExternalLoginInfoAsync();
+ if (info == null)
+ {
+ ErrorMessage = "Error loading external login information during confirmation.";
+ return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
+ }
+
+ if (ModelState.IsValid)
+ {
+ var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email };
+ var result = await _userManager.CreateAsync(user);
+ if (result.Succeeded)
+ {
+ result = await _userManager.AddLoginAsync(user, info);
+ if (result.Succeeded)
+ {
+ await _signInManager.SignInAsync(user, isPersistent: false);
+ _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
+ return LocalRedirect(returnUrl);
+ }
+ }
+ foreach (var error in result.Errors)
+ {
+ ModelState.AddModelError(string.Empty, error.Description);
+ }
+ }
+
+ LoginProvider = info.LoginProvider;
+ ReturnUrl = returnUrl;
+ return Page();
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/ForgotPassword.cshtml b/Areas/Identity/Pages/Account/ForgotPassword.cshtml
new file mode 100644
index 0000000..1342aa7
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ForgotPassword.cshtml
@@ -0,0 +1,26 @@
+@page
+@model ForgotPasswordModel
+@{
+ ViewData["Title"] = "Forgot your password?";
+}
+
+
@ViewData["Title"]
+
Enter your email.
+
+
+
+
+
+
+
+@section Scripts {
+
+}
diff --git a/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs b/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs
new file mode 100644
index 0000000..72b20bd
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ForgotPasswordModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly IEmailSender _emailSender;
+
+ public ForgotPasswordModel(UserManager userManager, IEmailSender emailSender)
+ {
+ _userManager = userManager;
+ _emailSender = emailSender;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [EmailAddress]
+ public string Email { get; set; }
+ }
+
+ public async Task OnPostAsync()
+ {
+ if (ModelState.IsValid)
+ {
+ var user = await _userManager.FindByEmailAsync(Input.Email);
+ if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
+ {
+ // Don't reveal that the user does not exist or is not confirmed
+ return RedirectToPage("./ForgotPasswordConfirmation");
+ }
+
+ // For more information on how to enable account confirmation and password reset please
+ // visit https://go.microsoft.com/fwlink/?LinkID=532713
+ var code = await _userManager.GeneratePasswordResetTokenAsync(user);
+ var callbackUrl = Url.Page(
+ "/Account/ResetPassword",
+ pageHandler: null,
+ values: new { code },
+ protocol: Request.Scheme);
+
+ await _emailSender.SendEmailAsync(
+ Input.Email,
+ "Reset Password",
+ $"Please reset your password by clicking here.");
+
+ return RedirectToPage("./ForgotPasswordConfirmation");
+ }
+
+ return Page();
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml b/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml
new file mode 100644
index 0000000..9468da0
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml
@@ -0,0 +1,11 @@
+@page
+@model ForgotPasswordConfirmation
+@{
+ ViewData["Title"] = "Forgot password confirmation";
+}
+
+
@ViewData["Title"]
+
+ Please check your email to reset your password.
+
+ There are no external authentication services configured. See this article
+ for details on setting up this ASP.NET application to support logging in via external services.
+
+
+ }
+ else
+ {
+
+ }
+ }
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Login.cshtml.cs b/Areas/Identity/Pages/Account/Login.cshtml.cs
new file mode 100644
index 0000000..bfee255
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Login.cshtml.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LoginModel : PageModel
+ {
+ private readonly SignInManager _signInManager;
+ private readonly UserManager _userManager;
+
+ private readonly ILogger _logger;
+
+ public LoginModel(SignInManager signInManager, UserManager userManager,
+ ILogger logger)
+ {
+ _signInManager = signInManager;
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public IList ExternalLogins { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ [TempData]
+ public string ErrorMessage { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [Display(Name = "Username/Email")]
+ public string Username_Email { get; set; }
+
+ [Required]
+ [DataType(DataType.Password)]
+ public string Password { get; set; }
+
+ [Display(Name = "Remember me?")]
+ public bool RememberMe { get; set; }
+ }
+
+ public async Task OnGetAsync(string returnUrl = null)
+ {
+ if (!string.IsNullOrEmpty(ErrorMessage))
+ {
+ ModelState.AddModelError(string.Empty, ErrorMessage);
+ }
+
+ returnUrl = returnUrl ?? Url.Content("~/");
+
+ // Clear the existing external cookie to ensure a clean login process
+ await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
+
+ ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
+
+ ReturnUrl = returnUrl;
+ }
+
+ public async Task OnPostAsync(string returnUrl = null)
+ {
+ returnUrl = returnUrl ?? Url.Content("~/");
+
+ if (ModelState.IsValid)
+ {
+ // This doesn't count login failures towards account lockout
+ // To enable password failures to trigger account lockout, set lockoutOnFailure: true
+ var user = await _userManager.FindByNameAsync(Input.Username_Email) ?? await _userManager.FindByEmailAsync(Input.Username_Email);
+ if (user == null)
+ {
+ ModelState.AddModelError(string.Empty, "User not found.");
+ return Page();
+ }
+ var result = await _signInManager.PasswordSignInAsync(user, Input.Password, Input.RememberMe, lockoutOnFailure: true);
+ if (result.Succeeded)
+ {
+ _logger.LogInformation("User logged in.");
+ return LocalRedirect(returnUrl);
+ }
+ if (result.RequiresTwoFactor)
+ {
+ return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
+ }
+ if (result.IsLockedOut)
+ {
+ _logger.LogWarning("User account locked out.");
+ return RedirectToPage("./Lockout");
+ }
+ else
+ {
+ ModelState.AddModelError(string.Empty, "Password is incorrect.");
+ return Page();
+ }
+ }
+
+ // If we got this far, something failed, redisplay form
+ return Page();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/LoginWith2fa.cshtml b/Areas/Identity/Pages/Account/LoginWith2fa.cshtml
new file mode 100644
index 0000000..a9d25fd
--- /dev/null
+++ b/Areas/Identity/Pages/Account/LoginWith2fa.cshtml
@@ -0,0 +1,41 @@
+@page
+@model LoginWith2faModel
+@{
+ ViewData["Title"] = "Two-factor authentication";
+}
+
+
@ViewData["Title"]
+
+
Your login is protected with an authenticator app. Enter your authenticator code below.
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs b/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs
new file mode 100644
index 0000000..0be4d06
--- /dev/null
+++ b/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LoginWith2faModel : PageModel
+ {
+ private readonly SignInManager _signInManager;
+ private readonly ILogger _logger;
+
+ public LoginWith2faModel(SignInManager signInManager, ILogger logger)
+ {
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public bool RememberMe { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
+ [DataType(DataType.Text)]
+ [Display(Name = "Authenticator code")]
+ public string TwoFactorCode { get; set; }
+
+ [Display(Name = "Remember this machine")]
+ public bool RememberMachine { get; set; }
+ }
+
+ public async Task OnGetAsync(bool rememberMe, string returnUrl = null)
+ {
+ // Ensure the user has gone through the username & password screen first
+ var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+
+ if (user == null)
+ {
+ throw new InvalidOperationException($"Unable to load two-factor authentication user.");
+ }
+
+ ReturnUrl = returnUrl;
+ RememberMe = rememberMe;
+
+ return Page();
+ }
+
+ public async Task OnPostAsync(bool rememberMe, string returnUrl = null)
+ {
+ if (!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ returnUrl = returnUrl ?? Url.Content("~/");
+
+ var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+ if (user == null)
+ {
+ throw new InvalidOperationException($"Unable to load two-factor authentication user.");
+ }
+
+ var authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);
+
+ var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe, Input.RememberMachine);
+
+ if (result.Succeeded)
+ {
+ _logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id);
+ return LocalRedirect(returnUrl);
+ }
+ else if (result.IsLockedOut)
+ {
+ _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
+ return RedirectToPage("./Lockout");
+ }
+ else
+ {
+ _logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
+ ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
+ return Page();
+ }
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml b/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml
new file mode 100644
index 0000000..abd45aa
--- /dev/null
+++ b/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml
@@ -0,0 +1,29 @@
+@page
+@model LoginWithRecoveryCodeModel
+@{
+ ViewData["Title"] = "Recovery code verification";
+}
+
+
@ViewData["Title"]
+
+
+ You have requested to log in with a recovery code. This login will not be remembered until you provide
+ an authenticator app code at log in or disable 2FA and log in again.
+
+
+
+
+
+
+
+ @section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs b/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs
new file mode 100644
index 0000000..ccb2d86
--- /dev/null
+++ b/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LoginWithRecoveryCodeModel : PageModel
+ {
+ private readonly SignInManager _signInManager;
+ private readonly ILogger _logger;
+
+ public LoginWithRecoveryCodeModel(SignInManager signInManager, ILogger logger)
+ {
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ public class InputModel
+ {
+ [BindProperty]
+ [Required]
+ [DataType(DataType.Text)]
+ [Display(Name = "Recovery Code")]
+ public string RecoveryCode { get; set; }
+ }
+
+ public async Task OnGetAsync(string returnUrl = null)
+ {
+ // Ensure the user has gone through the username & password screen first
+ var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+ if (user == null)
+ {
+ throw new InvalidOperationException($"Unable to load two-factor authentication user.");
+ }
+
+ ReturnUrl = returnUrl;
+
+ return Page();
+ }
+
+ public async Task OnPostAsync(string returnUrl = null)
+ {
+ if (!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+ if (user == null)
+ {
+ throw new InvalidOperationException($"Unable to load two-factor authentication user.");
+ }
+
+ var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty);
+
+ var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode);
+
+ if (result.Succeeded)
+ {
+ _logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", user.Id);
+ return LocalRedirect(returnUrl ?? Url.Content("~/"));
+ }
+ if (result.IsLockedOut)
+ {
+ _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
+ return RedirectToPage("./Lockout");
+ }
+ else
+ {
+ _logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id);
+ ModelState.AddModelError(string.Empty, "Invalid recovery code entered.");
+ return Page();
+ }
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/Logout.cshtml b/Areas/Identity/Pages/Account/Logout.cshtml
new file mode 100644
index 0000000..cb864ef
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Logout.cshtml
@@ -0,0 +1,10 @@
+@page
+@model LogoutModel
+@{
+ ViewData["Title"] = "Log out";
+}
+
+
+
@ViewData["Title"]
+
You have successfully logged out of the application.
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs b/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
new file mode 100644
index 0000000..057b434
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class ChangePasswordModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly SignInManager _signInManager;
+ private readonly ILogger _logger;
+
+ public ChangePasswordModel(
+ UserManager userManager,
+ SignInManager signInManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [DataType(DataType.Password)]
+ [Display(Name = "Current password")]
+ public string OldPassword { get; set; }
+
+ [Required]
+ [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
+ [DataType(DataType.Password)]
+ [Display(Name = "New password")]
+ public string NewPassword { get; set; }
+
+ [DataType(DataType.Password)]
+ [Display(Name = "Confirm new password")]
+ [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
+ public string ConfirmPassword { get; set; }
+ }
+
+ public async Task OnGetAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var hasPassword = await _userManager.HasPasswordAsync(user);
+ if (!hasPassword)
+ {
+ return RedirectToPage("./SetPassword");
+ }
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ if (!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
+ if (!changePasswordResult.Succeeded)
+ {
+ foreach (var error in changePasswordResult.Errors)
+ {
+ ModelState.AddModelError(string.Empty, error.Description);
+ }
+ return Page();
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ _logger.LogInformation("User changed their password successfully.");
+ StatusMessage = "Your password has been changed.";
+
+ return RedirectToPage();
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml b/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml
new file mode 100644
index 0000000..4a8eb27
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml
@@ -0,0 +1,34 @@
+@page
+@model DeletePersonalDataModel
+@{
+ ViewData["Title"] = "Delete Personal Data";
+ ViewData["ActivePage"] = ManageNavPages.DeletePersonalData;
+}
+
+
@ViewData["Title"]
+
+
+
+
+ Deleting this data will permanently remove your account, and this cannot be recovered.
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs b/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs
new file mode 100644
index 0000000..3f707d5
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs
@@ -0,0 +1,85 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class DeletePersonalDataModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly SignInManager _signInManager;
+ private readonly ILogger _logger;
+
+ public DeletePersonalDataModel(
+ UserManager userManager,
+ SignInManager signInManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [DataType(DataType.Password)]
+ public string Password { get; set; }
+ }
+
+ public bool RequirePassword { get; set; }
+
+ public async Task OnGet()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ RequirePassword = await _userManager.HasPasswordAsync(user);
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ RequirePassword = await _userManager.HasPasswordAsync(user);
+ if (RequirePassword)
+ {
+ if (!await _userManager.CheckPasswordAsync(user, Input.Password))
+ {
+ ModelState.AddModelError(string.Empty, "Password not correct.");
+ return Page();
+ }
+ }
+
+ var result = await _userManager.DeleteAsync(user);
+ var userId = await _userManager.GetUserIdAsync(user);
+ if (!result.Succeeded)
+ {
+ throw new InvalidOperationException($"Unexpected error occurred deleteing user with ID '{userId}'.");
+ }
+
+ await _signInManager.SignOutAsync();
+
+ _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);
+
+ return Redirect("~/");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml b/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml
new file mode 100644
index 0000000..f64f11e
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml
@@ -0,0 +1,26 @@
+@page
+@model Disable2faModel
+@{
+ ViewData["Title"] = "Disable two-factor authentication (2FA)";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+
@ViewData["Title"]
+
+
+
+
+ This action only disables 2FA.
+
+
+ Disabling 2FA does not change the keys used in authenticator apps. If you wish to change the key
+ used in an authenticator app you should reset your authenticator keys.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs b/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs
new file mode 100644
index 0000000..184a23e
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class Disable2faModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+
+ public Disable2faModel(
+ UserManager userManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGet()
+ {
+ 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();
+ }
+
+ public async Task OnPostAsync()
+ {
+ 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");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml b/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml
new file mode 100644
index 0000000..0bf709f
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml
@@ -0,0 +1,12 @@
+@page
+@model DownloadPersonalDataModel
+@{
+ ViewData["Title"] = "Download Your Data";
+ ViewData["ActivePage"] = ManageNavPages.DownloadPersonalData;
+}
+
+
@ViewData["Title"]
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs b/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs
new file mode 100644
index 0000000..d145d3b
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class DownloadPersonalDataModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+
+ public DownloadPersonalDataModel(
+ UserManager userManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ public async Task OnPostAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ _logger.LogInformation("User with ID '{UserId}' asked for their personal data.", _userManager.GetUserId(User));
+
+ // Only include personal data for download
+ var personalData = new Dictionary();
+ var personalDataProps = typeof(ApplicationUser).GetProperties().Where(
+ prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));
+ foreach (var p in personalDataProps)
+ {
+ personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
+ }
+
+ Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
+ return new FileContentResult(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(personalData)), "text/json");
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml b/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml
new file mode 100644
index 0000000..abdd39c
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml
@@ -0,0 +1,54 @@
+@page
+@model EnableAuthenticatorModel
+@{
+ ViewData["Title"] = "Configure authenticator app";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+
@ViewData["Title"]
+
+
To use an authenticator app go through the following steps:
+
+
+
+ Download a two-factor authenticator app like Microsoft Authenticator for
+ Windows Phone,
+ Android and
+ iOS or
+ Google Authenticator for
+ Android and
+ iOS.
+
+
+
+
Scan the QR Code or enter this key @Model.SharedKey into your two factor authenticator app. Spaces and casing do not matter.
+
To enable QR code generation please read our documentation.
+
+
+
+
+
+ Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
+ with a unique code. Enter the code in the confirmation box below.
+
+
+
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs b/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs
new file mode 100644
index 0000000..19326ac
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs
@@ -0,0 +1,158 @@
+using System;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class EnableAuthenticatorModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+ private readonly UrlEncoder _urlEncoder;
+
+ private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
+
+ public EnableAuthenticatorModel(
+ UserManager userManager,
+ ILogger logger,
+ UrlEncoder urlEncoder)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ _urlEncoder = urlEncoder;
+ }
+
+ public string SharedKey { get; set; }
+
+ public string AuthenticatorUri { get; set; }
+
+ [TempData]
+ public string[] RecoveryCodes { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
+ [DataType(DataType.Text)]
+ [Display(Name = "Verification Code")]
+ public string Code { get; set; }
+ }
+
+ public async Task OnGetAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ await LoadSharedKeyAndQrCodeUriAsync(user);
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ if (!ModelState.IsValid)
+ {
+ await LoadSharedKeyAndQrCodeUriAsync(user);
+ return Page();
+ }
+
+ // Strip spaces and hypens
+ var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
+
+ var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
+ user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);
+
+ if (!is2faTokenValid)
+ {
+ ModelState.AddModelError("Input.Code", "Verification code is invalid.");
+ await LoadSharedKeyAndQrCodeUriAsync(user);
+ return Page();
+ }
+
+ await _userManager.SetTwoFactorEnabledAsync(user, true);
+ var userId = await _userManager.GetUserIdAsync(user);
+ _logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);
+
+ 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(ApplicationUser user)
+ {
+ // Load the authenticator key & QR code URI to display on the form
+ var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
+ if (string.IsNullOrEmpty(unformattedKey))
+ {
+ await _userManager.ResetAuthenticatorKeyAsync(user);
+ unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
+ }
+
+ SharedKey = FormatKey(unformattedKey);
+
+ var email = await _userManager.GetEmailAsync(user);
+ AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
+ }
+
+ private string FormatKey(string unformattedKey)
+ {
+ var result = new StringBuilder();
+ int currentPosition = 0;
+ while (currentPosition + 4 < unformattedKey.Length)
+ {
+ result.Append(unformattedKey.Substring(currentPosition, 4)).Append(" ");
+ currentPosition += 4;
+ }
+ if (currentPosition < unformattedKey.Length)
+ {
+ result.Append(unformattedKey.Substring(currentPosition));
+ }
+
+ return result.ToString().ToLowerInvariant();
+ }
+
+ private string GenerateQrCodeUri(string email, string unformattedKey)
+ {
+ return string.Format(
+ AuthenticatorUriFormat,
+ _urlEncoder.Encode("RazorStripe"),
+ _urlEncoder.Encode(email),
+ unformattedKey);
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml b/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml
new file mode 100644
index 0000000..31027a6
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml
@@ -0,0 +1,52 @@
+@page
+@model ExternalLoginsModel
+@{
+ ViewData["Title"] = "Manage your external logins";
+}
+
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+@if (Model.CurrentLogins?.Count > 0)
+{
+
Registered Logins
+
+
+ @foreach (var login in Model.CurrentLogins)
+ {
+
+
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs b/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs
new file mode 100644
index 0000000..6ce1c11
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class ExternalLoginsModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly SignInManager _signInManager;
+
+ public ExternalLoginsModel(
+ UserManager userManager,
+ SignInManager signInManager)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ }
+
+ public IList CurrentLogins { get; set; }
+
+ public IList OtherLogins { get; set; }
+
+ public bool ShowRemoveButton { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGetAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ CurrentLogins = await _userManager.GetLoginsAsync(user);
+ OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
+ .Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider))
+ .ToList();
+ ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1;
+ return Page();
+ }
+
+ public async Task OnPostRemoveLoginAsync(string loginProvider, string providerKey)
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
+ if (!result.Succeeded)
+ {
+ var userId = await _userManager.GetUserIdAsync(user);
+ throw new InvalidOperationException($"Unexpected error occurred removing external login for user with ID '{userId}'.");
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "The external login was removed.";
+ return RedirectToPage();
+ }
+
+ public async Task OnPostLinkLoginAsync(string provider)
+ {
+ // Clear the existing external cookie to ensure a clean login process
+ await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
+
+ // Request a redirect to the external login provider to link a login for the current user
+ var redirectUrl = Url.Page("./ExternalLogins", pageHandler: "LinkLoginCallback");
+ var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));
+ return new ChallengeResult(provider, properties);
+ }
+
+ public async Task OnGetLinkLoginCallbackAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var info = await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user));
+ if (info == null)
+ {
+ throw new InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
+ }
+
+ var result = await _userManager.AddLoginAsync(user, info);
+ if (!result.Succeeded)
+ {
+ throw new InvalidOperationException($"Unexpected error occurred adding external login for user with ID '{user.Id}'.");
+ }
+
+ // Clear the existing external cookie to ensure a clean login process
+ await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
+
+ StatusMessage = "The external login was added.";
+ return RedirectToPage();
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml b/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml
new file mode 100644
index 0000000..7d8d822
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml
@@ -0,0 +1,27 @@
+@page
+@model GenerateRecoveryCodesModel
+@{
+ ViewData["Title"] = "Generate two-factor authentication (2FA) recovery codes";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+
@ViewData["Title"]
+
+
+
+ Put these codes in a safe place.
+
+
+ If you lose your device and don't have the recovery codes you will lose access to your account.
+
+
+ Generating new recovery codes does not change the keys used in authenticator apps. If you wish to change the key
+ used in an authenticator app you should reset your authenticator keys.
+
+
+
+
+
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs b/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
new file mode 100644
index 0000000..b1407cd
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class GenerateRecoveryCodesModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+
+ public GenerateRecoveryCodesModel(
+ UserManager userManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ [TempData]
+ public string[] RecoveryCodes { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGetAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
+ if (!isTwoFactorEnabled)
+ {
+ var userId = await _userManager.GetUserIdAsync(user);
+ throw new InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' because they do not have 2FA enabled.");
+ }
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
+ var userId = await _userManager.GetUserIdAsync(user);
+ if (!isTwoFactorEnabled)
+ {
+ throw new InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' as they do not have 2FA enabled.");
+ }
+
+ var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
+ RecoveryCodes = recoveryCodes.ToArray();
+
+ _logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", userId);
+ StatusMessage = "You have generated new recovery codes.";
+ return RedirectToPage("./ShowRecoveryCodes");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/Index.cshtml b/Areas/Identity/Pages/Account/Manage/Index.cshtml
new file mode 100644
index 0000000..76e987c
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/Index.cshtml
@@ -0,0 +1,57 @@
+@page
+@model IndexModel
+@{
+ ViewData["Title"] = "Profile";
+}
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs b/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs
new file mode 100644
index 0000000..279c0c2
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs
@@ -0,0 +1,35 @@
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class PersonalDataModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly ILogger _logger;
+
+ public PersonalDataModel(
+ UserManager userManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ public async Task OnGet()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ return Page();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml b/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml
new file mode 100644
index 0000000..d4eb529
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml
@@ -0,0 +1,24 @@
+@page
+@model ResetAuthenticatorModel
+@{
+ ViewData["Title"] = "Reset authenticator key";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+
@ViewData["Title"]
+
+
+
+ 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.
+ If you do not complete your authenticator app configuration you may lose access to your account.
+
+
+
+
+
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs b/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs
new file mode 100644
index 0000000..64e5876
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using RazorStripe.Data;
+using RazorStripe.Data.Models;
+
+namespace RazorStripe.Areas.Identity.Pages.Account.Manage
+{
+ public class ResetAuthenticatorModel : PageModel
+ {
+ UserManager _userManager;
+ private readonly SignInManager _signInManager;
+ ILogger _logger;
+
+ public ResetAuthenticatorModel(
+ UserManager userManager,
+ SignInManager signInManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGet()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ await _userManager.SetTwoFactorEnabledAsync(user, false);
+ await _userManager.ResetAuthenticatorKeyAsync(user);
+ _logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", user.Id);
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.";
+
+ return RedirectToPage("./EnableAuthenticator");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml b/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml
new file mode 100644
index 0000000..eadd2f2
--- /dev/null
+++ b/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml
@@ -0,0 +1,35 @@
+@page
+@model SetPasswordModel
+@{
+ ViewData["Title"] = "Set password";
+ ViewData["ActivePage"] = ManageNavPages.ChangePassword;
+}
+
+
diff --git a/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs b/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs
new file mode 100644
index 0000000..3c35680
--- /dev/null
+++ b/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace RazorStripe.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ResetPasswordConfirmationModel : PageModel
+ {
+ public void OnGet()
+ {
+
+ }
+ }
+}
diff --git a/Areas/Identity/Pages/Account/_ViewImports.cshtml b/Areas/Identity/Pages/Account/_ViewImports.cshtml
new file mode 100644
index 0000000..9c64c25
--- /dev/null
+++ b/Areas/Identity/Pages/Account/_ViewImports.cshtml
@@ -0,0 +1 @@
+@using RazorStripe.Areas.Identity.Pages.Account
\ No newline at end of file
diff --git a/Areas/Identity/Pages/Error.cshtml b/Areas/Identity/Pages/Error.cshtml
new file mode 100644
index 0000000..b1f3143
--- /dev/null
+++ b/Areas/Identity/Pages/Error.cshtml
@@ -0,0 +1,23 @@
+@page
+@model ErrorModel
+@{
+ ViewData["Title"] = "Error";
+}
+
+
Error.
+
An error occurred while processing your request.
+
+@if (Model.ShowRequestId)
+{
+
+ Request ID:@Model.RequestId
+
+}
+
+
Development Mode
+
+ Swapping to Development environment will display more detailed information about the error that occurred.
+
+
+ Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
+