diff --git a/Marechai/Areas/Identity/IdentityHostingStartup.cs b/Marechai/Areas/Identity/IdentityHostingStartup.cs
new file mode 100644
index 00000000..c67369a8
--- /dev/null
+++ b/Marechai/Areas/Identity/IdentityHostingStartup.cs
@@ -0,0 +1,12 @@
+using Marechai.Areas.Identity;
+using Microsoft.AspNetCore.Hosting;
+
+[assembly: HostingStartup(typeof(IdentityHostingStartup))]
+
+namespace Marechai.Areas.Identity
+{
+ public class IdentityHostingStartup : IHostingStartup
+ {
+ public void Configure(IWebHostBuilder builder) => builder.ConfigureServices((context, services) => { });
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml b/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml
new file mode 100644
index 00000000..b9112de2
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml
@@ -0,0 +1,9 @@
+@page
+@model AccessDeniedModel
+@{
+ ViewData["Title"] = "Access denied";
+}
+
+
@ViewData["Title"]
+
You do not have access to this resource.
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml.cs
new file mode 100644
index 00000000..3060a696
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/AccessDenied.cshtml.cs
@@ -0,0 +1,9 @@
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ public class AccessDeniedModel : PageModel
+ {
+ public void OnGet() { }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml b/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
new file mode 100644
index 00000000..a78af931
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
@@ -0,0 +1,6 @@
+@page
+@model ConfirmEmailModel
+@{
+ ViewData["Title"] = "Confirm email";
+}
+
@ViewData["Title"]
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
new file mode 100644
index 00000000..61f938bf
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
@@ -0,0 +1,44 @@
+using System.Text;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ConfirmEmailModel : PageModel
+ {
+ readonly UserManager _userManager;
+
+ public ConfirmEmailModel(UserManager userManager) => _userManager = userManager;
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGetAsync(string userId, string code)
+ {
+ if(userId == null ||
+ code == null)
+ {
+ return RedirectToPage("/Index");
+ }
+
+ ApplicationUser user = await _userManager.FindByIdAsync(userId);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{userId}'.");
+ }
+
+ code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
+ IdentityResult result = await _userManager.ConfirmEmailAsync(user, code);
+ StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email.";
+
+ return Page();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml b/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml
new file mode 100644
index 00000000..1fdc107a
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml
@@ -0,0 +1,7 @@
+@page
+@model ConfirmEmailChangeModel
+@{
+ ViewData["Title"] = "Confirm email change";
+}
+
@ViewData["Title"]
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs
new file mode 100644
index 00000000..b5e77e53
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs
@@ -0,0 +1,71 @@
+using System.Text;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ConfirmEmailChangeModel : PageModel
+ {
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public ConfirmEmailChangeModel(UserManager userManager,
+ SignInManager signInManager)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGetAsync(string userId, string email, string code)
+ {
+ if(userId == null ||
+ email == null ||
+ code == null)
+ {
+ return RedirectToPage("/Index");
+ }
+
+ ApplicationUser user = await _userManager.FindByIdAsync(userId);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{userId}'.");
+ }
+
+ code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
+ IdentityResult result = await _userManager.ChangeEmailAsync(user, email, code);
+
+ if(!result.Succeeded)
+ {
+ StatusMessage = "Error changing email.";
+
+ return Page();
+ }
+
+ // In our UI email and user name are one and the same, so when we update the email
+ // we need to update the user name.
+ IdentityResult setUserNameResult = await _userManager.SetUserNameAsync(user, email);
+
+ if(!setUserNameResult.Succeeded)
+ {
+ StatusMessage = "Error changing user name.";
+
+ return Page();
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "Thank you for confirming your email change.";
+
+ return Page();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml b/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml
new file mode 100644
index 00000000..31ec095b
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml
@@ -0,0 +1,31 @@
+@page
+@model ExternalLoginModel
+@{
+ ViewData["Title"] = "Register";
+}
+
@ViewData["Title"]
+
Associate your @Model.ProviderDisplayName account.
+
+
+ You've successfully authenticated with
+ @Model.ProviderDisplayName.
+ Please enter an email address for this site below and click the Register button to finish
+ logging in.
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs
new file mode 100644
index 00000000..61b52d27
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs
@@ -0,0 +1,200 @@
+using System.ComponentModel.DataAnnotations;
+using System.Security.Claims;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.Extensions.Logging;
+using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ExternalLoginModel : PageModel
+ {
+ readonly IEmailSender _emailSender;
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public ExternalLoginModel(SignInManager signInManager,
+ UserManager userManager, ILogger logger,
+ IEmailSender emailSender)
+ {
+ _signInManager = signInManager;
+ _userManager = userManager;
+ _logger = logger;
+ _emailSender = emailSender;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public string ProviderDisplayName { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ [TempData]
+ public string ErrorMessage { get; set; }
+
+ public IActionResult OnGetAsync() => RedirectToPage("./Login");
+
+ public IActionResult OnPost(string provider, string returnUrl = null)
+ {
+ // Request a redirect to the external login provider.
+ string redirectUrl = Url.Page("./ExternalLogin", "Callback", new
+ {
+ returnUrl
+ });
+
+ AuthenticationProperties 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
+ });
+ }
+
+ ExternalLoginInfo 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.
+ SignInResult result =
+ await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false, 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");
+ }
+
+ // If the user does not have an account, then ask the user to create an account.
+ ReturnUrl = returnUrl;
+ ProviderDisplayName = info.ProviderDisplayName;
+
+ 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
+ ExternalLoginInfo 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
+ };
+
+ IdentityResult result = await _userManager.CreateAsync(user);
+
+ if(result.Succeeded)
+ {
+ result = await _userManager.AddLoginAsync(user, info);
+
+ if(result.Succeeded)
+ {
+ _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
+
+ string userId = await _userManager.GetUserIdAsync(user);
+ string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+ code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+
+ string callbackUrl = Url.Page("/Account/ConfirmEmail", null, new
+ {
+ area = "Identity", userId, code
+ }, Request.Scheme);
+
+ await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
+ $"Please confirm your account by clicking here.");
+
+ // If account confirmation is required, we need to show the link if we don't have a real email sender
+ if(_userManager.Options.SignIn.RequireConfirmedAccount)
+ {
+ return RedirectToPage("./RegisterConfirmation", new
+ {
+ Input.Email
+ });
+ }
+
+ await _signInManager.SignInAsync(user, false, info.LoginProvider);
+
+ return LocalRedirect(returnUrl);
+ }
+ }
+
+ foreach(IdentityError error in result.Errors)
+ {
+ ModelState.AddModelError(string.Empty, error.Description);
+ }
+ }
+
+ ProviderDisplayName = info.ProviderDisplayName;
+ ReturnUrl = returnUrl;
+
+ return Page();
+ }
+
+ public class InputModel
+ {
+ [Required, EmailAddress]
+ public string Email { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml b/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml
new file mode 100644
index 00000000..ca9490be
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml
@@ -0,0 +1,25 @@
+@page
+@model ForgotPasswordModel
+@{
+ ViewData["Title"] = "Forgot your password?";
+}
+
@ViewData["Title"]
+
Enter your email.
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs
new file mode 100644
index 00000000..0e810a21
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs
@@ -0,0 +1,68 @@
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ForgotPasswordModel : PageModel
+ {
+ readonly IEmailSender _emailSender;
+ readonly UserManager _userManager;
+
+ public ForgotPasswordModel(UserManager userManager, IEmailSender emailSender)
+ {
+ _userManager = userManager;
+ _emailSender = emailSender;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public async Task OnPostAsync()
+ {
+ if(ModelState.IsValid)
+ {
+ ApplicationUser 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
+ string code = await _userManager.GeneratePasswordResetTokenAsync(user);
+ code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+
+ string callbackUrl = Url.Page("/Account/ResetPassword", null, new
+ {
+ area = "Identity", code
+ }, Request.Scheme);
+
+ await _emailSender.SendEmailAsync(Input.Email, "Reset Password",
+ $"Please reset your password by clicking here.");
+
+ return RedirectToPage("./ForgotPasswordConfirmation");
+ }
+
+ return Page();
+ }
+
+ public class InputModel
+ {
+ [Required, EmailAddress]
+ public string Email { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml b/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml
new file mode 100644
index 00000000..895f749e
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml
@@ -0,0 +1,9 @@
+@page
+@model ForgotPasswordConfirmation
+@{
+ ViewData["Title"] = "Forgot password confirmation";
+}
+
@ViewData["Title"]
+
+ Please check your email to reset your password.
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml.cs
new file mode 100644
index 00000000..7d7f0bb7
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ForgotPasswordConfirmation : PageModel
+ {
+ public void OnGet() { }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml b/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml
new file mode 100644
index 00000000..c7bdce32
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml
@@ -0,0 +1,9 @@
+@page
+@model LockoutModel
+@{
+ ViewData["Title"] = "Locked out";
+}
+
+
@ViewData["Title"]
+
This account has been locked out, please try again later.
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml.cs
new file mode 100644
index 00000000..bb48d8cb
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Lockout.cshtml.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LockoutModel : PageModel
+ {
+ public void OnGet() { }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/LogOut.cshtml b/Marechai/Areas/Identity/Pages/Account/LogOut.cshtml
index 2ae1ea3b..e38c0e86 100644
--- a/Marechai/Areas/Identity/Pages/Account/LogOut.cshtml
+++ b/Marechai/Areas/Identity/Pages/Account/LogOut.cshtml
@@ -1,7 +1,7 @@
@page
-@using Microsoft.AspNetCore.Identity
+@using Marechai.Database.Models
@attribute [IgnoreAntiforgeryToken]
-@inject SignInManager SignInManager
+@inject SignInManager SignInManager
@functions {
diff --git a/Marechai/Areas/Identity/Pages/Account/Login.cshtml b/Marechai/Areas/Identity/Pages/Account/Login.cshtml
new file mode 100644
index 00000000..f716b4ee
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Login.cshtml
@@ -0,0 +1,85 @@
+@page
+@model LoginModel
+
+@{
+ ViewData["Title"] = "Log in";
+}
+
+ 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.
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs
new file mode 100644
index 00000000..5756d6bd
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs
@@ -0,0 +1,102 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LoginWith2faModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+
+ 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 async Task OnGetAsync(bool rememberMe, string returnUrl = null)
+ {
+ // Ensure the user has gone through the username & password screen first
+ ApplicationUser 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("~/");
+
+ ApplicationUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+
+ if(user == null)
+ {
+ throw new InvalidOperationException("Unable to load two-factor authentication user.");
+ }
+
+ string authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);
+
+ SignInResult 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);
+ }
+
+ if(result.IsLockedOut)
+ {
+ _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
+
+ return RedirectToPage("./Lockout");
+ }
+
+ _logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
+ ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
+
+ return Page();
+ }
+
+ 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; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml b/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml
new file mode 100644
index 00000000..88e9cbf0
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml
@@ -0,0 +1,28 @@
+@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/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs
new file mode 100644
index 00000000..b3b9f41e
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs
@@ -0,0 +1,91 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LoginWithRecoveryCodeModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+
+ public LoginWithRecoveryCodeModel(SignInManager signInManager,
+ ILogger logger)
+ {
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ public async Task OnGetAsync(string returnUrl = null)
+ {
+ // Ensure the user has gone through the username & password screen first
+ ApplicationUser 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();
+ }
+
+ ApplicationUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
+
+ if(user == null)
+ {
+ throw new InvalidOperationException("Unable to load two-factor authentication user.");
+ }
+
+ string recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty);
+
+ SignInResult 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");
+ }
+
+ _logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id);
+ ModelState.AddModelError(string.Empty, "Invalid recovery code entered.");
+
+ return Page();
+ }
+
+ public class InputModel
+ {
+ [BindProperty, Required, DataType(DataType.Text), Display(Name = "Recovery Code")]
+ public string RecoveryCode { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Logout.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Logout.cshtml.cs
new file mode 100644
index 00000000..a3a90852
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Logout.cshtml.cs
@@ -0,0 +1,38 @@
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class LogoutModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+
+ public LogoutModel(SignInManager signInManager, ILogger logger)
+ {
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ public void OnGet() { }
+
+ public async Task OnPost(string returnUrl = null)
+ {
+ await _signInManager.SignOutAsync();
+ _logger.LogInformation("User logged out.");
+
+ if(returnUrl != null)
+ {
+ return LocalRedirect(returnUrl);
+ }
+
+ return RedirectToPage();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml
new file mode 100644
index 00000000..e5a268b5
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml
@@ -0,0 +1,35 @@
+@page
+@model ChangePasswordModel
+@{
+ ViewData["Title"] = "Change password";
+ ViewData["ActivePage"] = ManageNavPages.ChangePassword;
+}
+
@ViewData["Title"]
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
new file mode 100644
index 00000000..681dd9e0
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
@@ -0,0 +1,99 @@
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class ChangePasswordModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ 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 async Task OnGetAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ bool hasPassword = await _userManager.HasPasswordAsync(user);
+
+ if(!hasPassword)
+ {
+ return RedirectToPage("./SetPassword");
+ }
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ if(!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ IdentityResult changePasswordResult =
+ await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
+
+ if(!changePasswordResult.Succeeded)
+ {
+ foreach(IdentityError 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();
+ }
+
+ 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; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml
new file mode 100644
index 00000000..6aa3c747
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml
@@ -0,0 +1,30 @@
+@page
+@model DeletePersonalDataModel
+@{
+ ViewData["Title"] = "Delete Personal Data";
+ ViewData["ActivePage"] = ManageNavPages.PersonalData;
+}
+
@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/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs
new file mode 100644
index 00000000..fa00dcc6
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs
@@ -0,0 +1,88 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class DeletePersonalDataModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public DeletePersonalDataModel(UserManager userManager,
+ SignInManager signInManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public bool RequirePassword { get; set; }
+
+ public async Task OnGet()
+ {
+ ApplicationUser 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()
+ {
+ ApplicationUser 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, "Incorrect password.");
+
+ return Page();
+ }
+ }
+
+ IdentityResult result = await _userManager.DeleteAsync(user);
+ string userId = await _userManager.GetUserIdAsync(user);
+
+ if(!result.Succeeded)
+ {
+ throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
+ }
+
+ await _signInManager.SignOutAsync();
+
+ _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);
+
+ return Redirect("~/");
+ }
+
+ public class InputModel
+ {
+ [Required, DataType(DataType.Password)]
+ public string Password { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml
new file mode 100644
index 00000000..42dae504
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml
@@ -0,0 +1,23 @@
+@page
+@model Disable2faModel
+@{
+ ViewData["Title"] = "Disable two-factor authentication (2FA)";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+
@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/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs
new file mode 100644
index 00000000..a8bdf5ef
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Disable2fa.cshtml.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class Disable2faModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly UserManager _userManager;
+
+ public Disable2faModel(UserManager userManager, ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGet()
+ {
+ ApplicationUser 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()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ IdentityResult 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/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml
new file mode 100644
index 00000000..5ec6774b
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml
@@ -0,0 +1,11 @@
+@page
+@model DownloadPersonalDataModel
+@{
+ ViewData["Title"] = "Download Your Data";
+ ViewData["ActivePage"] = ManageNavPages.PersonalData;
+}
+
@ViewData["Title"]
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs
new file mode 100644
index 00000000..c8cc2c77
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/DownloadPersonalData.cshtml.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text.Json;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class DownloadPersonalDataModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly UserManager _userManager;
+
+ public DownloadPersonalDataModel(UserManager userManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ public async Task OnPostAsync()
+ {
+ ApplicationUser 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
+ Dictionary personalData = new Dictionary();
+
+ IEnumerable personalDataProps = typeof(ApplicationUser).
+ GetProperties().
+ Where(prop =>
+ Attribute.IsDefined(prop,
+ typeof(PersonalDataAttribute)));
+
+ foreach(PropertyInfo p in personalDataProps)
+ {
+ personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
+ }
+
+ IList logins = await _userManager.GetLoginsAsync(user);
+
+ foreach(UserLoginInfo l in logins)
+ {
+ personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
+ }
+
+ Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
+
+ return new FileContentResult(JsonSerializer.SerializeToUtf8Bytes(personalData), "application/json");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml
new file mode 100644
index 00000000..c4bb2a2e
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml
@@ -0,0 +1,42 @@
+@page
+@model EmailModel
+@{
+ ViewData["Title"] = "Manage Email";
+ ViewData["ActivePage"] = ManageNavPages.Email;
+}
+
@ViewData["Title"]
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml.cs
new file mode 100644
index 00000000..cfae9c22
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Email.cshtml.cs
@@ -0,0 +1,148 @@
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class EmailModel : PageModel
+ {
+ readonly IEmailSender _emailSender;
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public EmailModel(UserManager userManager, SignInManager signInManager,
+ IEmailSender emailSender)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _emailSender = emailSender;
+ }
+
+ public string Username { get; set; }
+
+ public string Email { get; set; }
+
+ public bool IsEmailConfirmed { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ async Task LoadAsync(ApplicationUser user)
+ {
+ string email = await _userManager.GetEmailAsync(user);
+ Email = email;
+
+ Input = new InputModel
+ {
+ NewEmail = email
+ };
+
+ IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
+ }
+
+ public async Task OnGetAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ await LoadAsync(user);
+
+ return Page();
+ }
+
+ public async Task OnPostChangeEmailAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ if(!ModelState.IsValid)
+ {
+ await LoadAsync(user);
+
+ return Page();
+ }
+
+ string email = await _userManager.GetEmailAsync(user);
+
+ if(Input.NewEmail != email)
+ {
+ string userId = await _userManager.GetUserIdAsync(user);
+ string code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail);
+
+ string callbackUrl = Url.Page("/Account/ConfirmEmailChange", null, new
+ {
+ userId, email = Input.NewEmail, code
+ }, Request.Scheme);
+
+ await _emailSender.SendEmailAsync(Input.NewEmail, "Confirm your email",
+ $"Please confirm your account by clicking here.");
+
+ StatusMessage = "Confirmation link to change email sent. Please check your email.";
+
+ return RedirectToPage();
+ }
+
+ StatusMessage = "Your email is unchanged.";
+
+ return RedirectToPage();
+ }
+
+ public async Task OnPostSendVerificationEmailAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ if(!ModelState.IsValid)
+ {
+ await LoadAsync(user);
+
+ return Page();
+ }
+
+ string userId = await _userManager.GetUserIdAsync(user);
+ string email = await _userManager.GetEmailAsync(user);
+ string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+ code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+
+ string callbackUrl = Url.Page("/Account/ConfirmEmail", null, new
+ {
+ area = "Identity", userId, code
+ }, Request.Scheme);
+
+ await _emailSender.SendEmailAsync(email, "Confirm your email",
+ $"Please confirm your account by clicking here.");
+
+ StatusMessage = "Verification email sent. Please check your email.";
+
+ return RedirectToPage();
+ }
+
+ public class InputModel
+ {
+ [Required, EmailAddress, Display(Name = "New email")]
+ public string NewEmail { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml
new file mode 100644
index 00000000..e91e2850
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml
@@ -0,0 +1,58 @@
+@page
+@model EnableAuthenticatorModel
+@{
+ ViewData["Title"] = "Configure authenticator app";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+
@ViewData["Title"]
+
+
To use an authenticator app go through the following steps:
+
+
+
+ Download a two-factor authenticator app like Microsoft Authenticator for
+ 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.
+
+ 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/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs
new file mode 100644
index 00000000..2e7e04a6
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs
@@ -0,0 +1,154 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class EnableAuthenticatorModel : PageModel
+ {
+ const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
+ readonly ILogger _logger;
+ readonly UrlEncoder _urlEncoder;
+ readonly UserManager _userManager;
+
+ 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 async Task OnGetAsync()
+ {
+ ApplicationUser 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()
+ {
+ ApplicationUser 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
+ string verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
+
+ bool 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);
+ string 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)
+ {
+ IEnumerable recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
+ RecoveryCodes = recoveryCodes.ToArray();
+
+ return RedirectToPage("./ShowRecoveryCodes");
+ }
+
+ return RedirectToPage("./TwoFactorAuthentication");
+ }
+
+ async Task LoadSharedKeyAndQrCodeUriAsync(ApplicationUser user)
+ {
+ // Load the authenticator key & QR code URI to display on the form
+ string unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
+
+ if(string.IsNullOrEmpty(unformattedKey))
+ {
+ await _userManager.ResetAuthenticatorKeyAsync(user);
+ unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
+ }
+
+ SharedKey = FormatKey(unformattedKey);
+
+ string email = await _userManager.GetEmailAsync(user);
+ AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
+ }
+
+ 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();
+ }
+
+ string GenerateQrCodeUri(string email, string unformattedKey) =>
+ string.Format(AuthenticatorUriFormat, _urlEncoder.Encode("Marechai"), _urlEncoder.Encode(email),
+ unformattedKey);
+
+ 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; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml
new file mode 100644
index 00000000..0fb5bfc6
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml
@@ -0,0 +1,52 @@
+@page
+@model ExternalLoginsModel
+@{
+ ViewData["Title"] = "Manage your external logins";
+ ViewData["ActivePage"] = ManageNavPages.ExternalLogins;
+}
+
+@if (Model.CurrentLogins?.Count > 0)
+{
+
Registered Logins
+
+
+ @foreach (var login in Model.CurrentLogins)
+ {
+
+
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs
new file mode 100644
index 00000000..e6cd80f2
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ExternalLogins.cshtml.cs
@@ -0,0 +1,127 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class ExternalLoginsModel : PageModel
+ {
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ 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()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound("Unable to load user with ID 'user.Id'.");
+ }
+
+ 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)
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound("Unable to load user with ID 'user.Id'.");
+ }
+
+ IdentityResult result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
+
+ if(!result.Succeeded)
+ {
+ StatusMessage = "The external login was not removed.";
+
+ return RedirectToPage();
+ }
+
+ 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
+ string redirectUrl = Url.Page("./ExternalLogins", "LinkLoginCallback");
+
+ AuthenticationProperties properties =
+ _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl,
+ _userManager.GetUserId(User));
+
+ return new ChallengeResult(provider, properties);
+ }
+
+ public async Task OnGetLinkLoginCallbackAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound("Unable to load user with ID 'user.Id'.");
+ }
+
+ ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync(user.Id);
+
+ if(info == null)
+ {
+ throw new
+ InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
+ }
+
+ IdentityResult result = await _userManager.AddLoginAsync(user, info);
+
+ if(!result.Succeeded)
+ {
+ StatusMessage =
+ "The external login was not added. External logins can only be associated with one account.";
+
+ return RedirectToPage();
+ }
+
+ // Clear the existing external cookie to ensure a clean login process
+ await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
+
+ StatusMessage = "The external login was added.";
+
+ return RedirectToPage();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml
new file mode 100644
index 00000000..0d4aecd3
--- /dev/null
+++ b/Marechai/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;
+}
+
+
@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/Marechai/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
new file mode 100644
index 00000000..a9de4aba
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class GenerateRecoveryCodesModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly UserManager _userManager;
+
+ 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()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ bool isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
+
+ if(!isTwoFactorEnabled)
+ {
+ string 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()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ bool isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
+ string 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.");
+ }
+
+ IEnumerable 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/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml
new file mode 100644
index 00000000..c8ec93fc
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml
@@ -0,0 +1,29 @@
+@page
+@model IndexModel
+@{
+ ViewData["Title"] = "Profile";
+ ViewData["ActivePage"] = ManageNavPages.Index;
+}
+
@ViewData["Title"]
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs
new file mode 100644
index 00000000..75096916
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs
@@ -0,0 +1,98 @@
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class IndexModel : PageModel
+ {
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public IndexModel(UserManager userManager, SignInManager signInManager)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ }
+
+ public string Username { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ async Task LoadAsync(ApplicationUser user)
+ {
+ string userName = await _userManager.GetUserNameAsync(user);
+ string phoneNumber = await _userManager.GetPhoneNumberAsync(user);
+
+ Username = userName;
+
+ Input = new InputModel
+ {
+ PhoneNumber = phoneNumber
+ };
+ }
+
+ public async Task OnGetAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ await LoadAsync(user);
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ if(!ModelState.IsValid)
+ {
+ await LoadAsync(user);
+
+ return Page();
+ }
+
+ string phoneNumber = await _userManager.GetPhoneNumberAsync(user);
+
+ if(Input.PhoneNumber != phoneNumber)
+ {
+ IdentityResult setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
+
+ if(!setPhoneResult.Succeeded)
+ {
+ StatusMessage = "Unexpected error when trying to set phone number.";
+
+ return RedirectToPage();
+ }
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "Your profile has been updated";
+
+ return RedirectToPage();
+ }
+
+ public class InputModel
+ {
+ [Phone, Display(Name = "Phone number")]
+ public string PhoneNumber { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs b/Marechai/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs
new file mode 100644
index 00000000..d02d625b
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs
@@ -0,0 +1,54 @@
+using System;
+using System.IO;
+using Microsoft.AspNetCore.Mvc.Rendering;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public static class ManageNavPages
+ {
+ public static string Index => "Index";
+
+ public static string Email => "Email";
+
+ public static string ChangePassword => "ChangePassword";
+
+ public static string DownloadPersonalData => "DownloadPersonalData";
+
+ public static string DeletePersonalData => "DeletePersonalData";
+
+ public static string ExternalLogins => "ExternalLogins";
+
+ public static string PersonalData => "PersonalData";
+
+ public static string TwoFactorAuthentication => "TwoFactorAuthentication";
+
+ public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
+
+ public static string EmailNavClass(ViewContext viewContext) => PageNavClass(viewContext, Email);
+
+ public static string ChangePasswordNavClass(ViewContext viewContext) =>
+ PageNavClass(viewContext, ChangePassword);
+
+ public static string DownloadPersonalDataNavClass(ViewContext viewContext) =>
+ PageNavClass(viewContext, DownloadPersonalData);
+
+ public static string DeletePersonalDataNavClass(ViewContext viewContext) =>
+ PageNavClass(viewContext, DeletePersonalData);
+
+ public static string ExternalLoginsNavClass(ViewContext viewContext) =>
+ PageNavClass(viewContext, ExternalLogins);
+
+ public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);
+
+ public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) =>
+ PageNavClass(viewContext, TwoFactorAuthentication);
+
+ static string PageNavClass(ViewContext viewContext, string page)
+ {
+ string activePage = viewContext.ViewData["ActivePage"] as string ??
+ Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName);
+
+ return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml
new file mode 100644
index 00000000..e8ff5180
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml
@@ -0,0 +1,25 @@
+@page
+@model PersonalDataModel
+@{
+ ViewData["Title"] = "Personal Data";
+ ViewData["ActivePage"] = ManageNavPages.PersonalData;
+}
+
@ViewData["Title"]
+
+
+
Your account contains personal data that you have given us. This page allows you to download or delete that data.
+
+ Deleting this data will permanently remove your account, and this cannot be recovered.
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs
new file mode 100644
index 00000000..525781f4
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/PersonalData.cshtml.cs
@@ -0,0 +1,33 @@
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class PersonalDataModel : PageModel
+ {
+ readonly ILogger _logger;
+ readonly UserManager _userManager;
+
+ public PersonalDataModel(UserManager userManager, ILogger logger)
+ {
+ _userManager = userManager;
+ _logger = logger;
+ }
+
+ public async Task OnGet()
+ {
+ ApplicationUser 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/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml
new file mode 100644
index 00000000..d54a4226
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml
@@ -0,0 +1,23 @@
+@page
+@model ResetAuthenticatorModel
+@{
+ ViewData["Title"] = "Reset authenticator key";
+ ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
+}
+
+
@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/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs
new file mode 100644
index 00000000..d046fa3e
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ResetAuthenticator.cshtml.cs
@@ -0,0 +1,61 @@
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class ResetAuthenticatorModel : PageModel
+ {
+ readonly SignInManager _signInManager;
+ readonly ILogger _logger;
+ readonly UserManager _userManager;
+
+ public ResetAuthenticatorModel(UserManager userManager,
+ SignInManager signInManager,
+ ILogger logger)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGet()
+ {
+ ApplicationUser 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()
+ {
+ ApplicationUser 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/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml
new file mode 100644
index 00000000..b5ada3d4
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml
@@ -0,0 +1,34 @@
+@page
+@model SetPasswordModel
+@{
+ ViewData["Title"] = "Set password";
+ ViewData["ActivePage"] = ManageNavPages.ChangePassword;
+}
+
Set your password
+
+
+ You do not have a local username/password for this site. Add a local
+ account so you can log in without an external login.
+
+
+
+
+
+
+
+@section Scripts {
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml.cs
new file mode 100644
index 00000000..8cbb5d9c
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/SetPassword.cshtml.cs
@@ -0,0 +1,90 @@
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account.Manage
+{
+ public class SetPasswordModel : PageModel
+ {
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public SetPasswordModel(UserManager userManager, SignInManager signInManager)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ public async Task OnGetAsync()
+ {
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ bool hasPassword = await _userManager.HasPasswordAsync(user);
+
+ if(hasPassword)
+ {
+ return RedirectToPage("./ChangePassword");
+ }
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ if(!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ ApplicationUser user = await _userManager.GetUserAsync(User);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ IdentityResult addPasswordResult = await _userManager.AddPasswordAsync(user, Input.NewPassword);
+
+ if(!addPasswordResult.Succeeded)
+ {
+ foreach(IdentityError error in addPasswordResult.Errors)
+ {
+ ModelState.AddModelError(string.Empty, error.Description);
+ }
+
+ return Page();
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "Your password has been set.";
+
+ return RedirectToPage();
+ }
+
+ public class InputModel
+ {
+ [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; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml b/Marechai/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml
new file mode 100644
index 00000000..cfba060f
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Manage/ShowRecoveryCodes.cshtml
@@ -0,0 +1,27 @@
+@page
+@model ShowRecoveryCodesModel
+@{
+ ViewData["Title"] = "Recovery codes";
+ ViewData["ActivePage"] = "TwoFactorAuthentication";
+}
+
+
@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.
+
+ 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/Marechai/Areas/Identity/Pages/Account/Register.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/Register.cshtml.cs
new file mode 100644
index 00000000..96ab57a0
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/Register.cshtml.cs
@@ -0,0 +1,116 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.Extensions.Logging;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class RegisterModel : PageModel
+ {
+ readonly IEmailSender _emailSender;
+ readonly ILogger _logger;
+ readonly SignInManager _signInManager;
+ readonly UserManager _userManager;
+
+ public RegisterModel(UserManager userManager, SignInManager signInManager,
+ ILogger logger, IEmailSender emailSender)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _logger = logger;
+ _emailSender = emailSender;
+ }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public string ReturnUrl { get; set; }
+
+ public IList ExternalLogins { get; set; }
+
+ public async Task OnGetAsync(string returnUrl = null)
+ {
+ ReturnUrl = returnUrl;
+ ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
+ }
+
+ public async Task OnPostAsync(string returnUrl = null)
+ {
+ returnUrl = returnUrl ?? Url.Content("~/");
+ ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
+
+ if(ModelState.IsValid)
+ {
+ var user = new ApplicationUser
+ {
+ UserName = Input.Email, Email = Input.Email
+ };
+
+ IdentityResult result = await _userManager.CreateAsync(user, Input.Password);
+
+ if(result.Succeeded)
+ {
+ _logger.LogInformation("User created a new account with password.");
+
+ string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+ code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+
+ string callbackUrl = Url.Page("/Account/ConfirmEmail", null, new
+ {
+ area = "Identity", userId = user.Id, code, returnUrl
+ }, Request.Scheme);
+
+ await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
+ $"Please confirm your account by clicking here.");
+
+ if(_userManager.Options.SignIn.RequireConfirmedAccount)
+ {
+ return RedirectToPage("RegisterConfirmation", new
+ {
+ email = Input.Email, returnUrl
+ });
+ }
+
+ await _signInManager.SignInAsync(user, false);
+
+ return LocalRedirect(returnUrl);
+ }
+
+ foreach(IdentityError error in result.Errors)
+ {
+ ModelState.AddModelError(string.Empty, error.Description);
+ }
+ }
+
+ // If we got this far, something failed, redisplay form
+ return Page();
+ }
+
+ public class InputModel
+ {
+ [Required, EmailAddress, Display(Name = "Email")]
+ public string Email { 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 = "Password")]
+ public string Password { get; set; }
+
+ [DataType(DataType.Password), Display(Name = "Confirm password"),
+ Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
+ public string ConfirmPassword { get; set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml b/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml
new file mode 100644
index 00000000..71732075
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml
@@ -0,0 +1,23 @@
+@page
+@model RegisterConfirmationModel
+@{
+ ViewData["Title"] = "Register confirmation";
+}
+
@ViewData["Title"]
+@{
+ if (Model.DisplayConfirmAccountLink)
+ {
+
+ This app does not currently have a real email sender registered, see
+ these docs for how to configure a real email sender.
+ Normally this would be emailed:
+ Click here to confirm your account
+
+ }
+ else
+ {
+
+ Please check your email to confirm your account.
+
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs
new file mode 100644
index 00000000..713a278c
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs
@@ -0,0 +1,65 @@
+using System.Text;
+using System.Threading.Tasks;
+using Marechai.Database.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class RegisterConfirmationModel : PageModel
+ {
+ readonly IEmailSender _sender;
+ readonly UserManager _userManager;
+
+ public RegisterConfirmationModel(UserManager userManager, IEmailSender sender)
+ {
+ _userManager = userManager;
+ _sender = sender;
+ }
+
+ public string Email { get; set; }
+
+ public bool DisplayConfirmAccountLink { get; set; }
+
+ public string EmailConfirmationUrl { get; set; }
+
+ public async Task OnGetAsync(string email, string returnUrl = null)
+ {
+ if(email == null)
+ {
+ return RedirectToPage("/Index");
+ }
+
+ ApplicationUser user = await _userManager.FindByEmailAsync(email);
+
+ if(user == null)
+ {
+ return NotFound($"Unable to load user with email '{email}'.");
+ }
+
+ Email = email;
+
+ // Once you add a real email sender, you should remove this code that lets you confirm the account
+ DisplayConfirmAccountLink = true;
+
+ if(DisplayConfirmAccountLink)
+ {
+ string userId = await _userManager.GetUserIdAsync(user);
+ string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+ code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+
+ EmailConfirmationUrl = Url.Page("/Account/ConfirmEmail", null, new
+ {
+ area = "Identity", userId, code, returnUrl
+ }, Request.Scheme);
+ }
+
+ return Page();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml b/Marechai/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml
new file mode 100644
index 00000000..347540b5
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml
@@ -0,0 +1,25 @@
+@page
+@model ResendEmailConfirmationModel
+@{
+ ViewData["Title"] = "Resend email confirmation";
+}
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs b/Marechai/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs
new file mode 100644
index 00000000..80177c09
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages.Account
+{
+ [AllowAnonymous]
+ public class ResetPasswordConfirmationModel : PageModel
+ {
+ public void OnGet() { }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/_StatusMessage.cshtml b/Marechai/Areas/Identity/Pages/Account/_StatusMessage.cshtml
new file mode 100644
index 00000000..ce970803
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/_StatusMessage.cshtml
@@ -0,0 +1,12 @@
+@model string
+
+@if (!string.IsNullOrEmpty(Model))
+{
+ var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
+
+
+ @Model
+
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Account/_ViewImports.cshtml b/Marechai/Areas/Identity/Pages/Account/_ViewImports.cshtml
new file mode 100644
index 00000000..ed71df8b
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Account/_ViewImports.cshtml
@@ -0,0 +1 @@
+@using Marechai.Areas.Identity.Pages.Account
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Error.cshtml b/Marechai/Areas/Identity/Pages/Error.cshtml
new file mode 100644
index 00000000..25b4cc7c
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Error.cshtml
@@ -0,0 +1,24 @@
+@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.
+
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Error.cshtml.cs b/Marechai/Areas/Identity/Pages/Error.cshtml.cs
new file mode 100644
index 00000000..57bfa7dc
--- /dev/null
+++ b/Marechai/Areas/Identity/Pages/Error.cshtml.cs
@@ -0,0 +1,17 @@
+using System.Diagnostics;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Marechai.Areas.Identity.Pages
+{
+ [AllowAnonymous, ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
+ public class ErrorModel : PageModel
+ {
+ public string RequestId { get; set; }
+
+ public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
+
+ public void OnGet() => RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml b/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
index d162021a..2839e8cd 100644
--- a/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
+++ b/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
@@ -1,30 +1,26 @@
-@using Marechai.Shared
-@using Microsoft.AspNetCore.Identity
-@using Microsoft.Extensions.Localization
-@inject SignInManager SignInManager
-@inject UserManager UserManager
-@inject StringLocalizer L
+@using Marechai.Database.Models
+@inject SignInManager SignInManager
+@inject UserManager UserManager
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
-