mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Use proper database context in new server.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using Aaru.Server.New.Components.Account.Pages;
|
||||
using Aaru.Server.New.Components.Account.Pages.Manage;
|
||||
using Aaru.Server.New.Data;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
@@ -23,8 +22,8 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
|
||||
RouteGroupBuilder accountGroup = endpoints.MapGroup("/Account");
|
||||
|
||||
accountGroup.MapPost("/PerformExternalLogin",
|
||||
(HttpContext context, [FromServices] SignInManager<ApplicationUser> signInManager,
|
||||
[FromForm] string provider, [FromForm] string returnUrl) =>
|
||||
(HttpContext context, [FromServices] SignInManager<IdentityUser> signInManager,
|
||||
[FromForm] string provider, [FromForm] string returnUrl) =>
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, StringValues>> query =
|
||||
[
|
||||
@@ -44,7 +43,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
|
||||
});
|
||||
|
||||
accountGroup.MapPost("/Logout",
|
||||
async (ClaimsPrincipal user, SignInManager<ApplicationUser> signInManager,
|
||||
async (ClaimsPrincipal user, SignInManager<IdentityUser> signInManager,
|
||||
[FromForm] string returnUrl) =>
|
||||
{
|
||||
await signInManager.SignOutAsync();
|
||||
@@ -55,7 +54,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
|
||||
RouteGroupBuilder manageGroup = accountGroup.MapGroup("/Manage").RequireAuthorization();
|
||||
|
||||
manageGroup.MapPost("/LinkExternalLogin",
|
||||
async (HttpContext context, [FromServices] SignInManager<ApplicationUser> signInManager,
|
||||
async (HttpContext context, [FromServices] SignInManager<IdentityUser> signInManager,
|
||||
[FromForm] string provider) =>
|
||||
{
|
||||
// Clear the existing external cookie to ensure a clean login process
|
||||
@@ -79,10 +78,10 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
|
||||
ILogger downloadLogger = loggerFactory.CreateLogger("DownloadPersonalData");
|
||||
|
||||
manageGroup.MapPost("/DownloadPersonalData",
|
||||
async (HttpContext context, [FromServices] UserManager<ApplicationUser> userManager,
|
||||
async (HttpContext context, [FromServices] UserManager<IdentityUser> userManager,
|
||||
[FromServices] AuthenticationStateProvider authenticationStateProvider) =>
|
||||
{
|
||||
ApplicationUser? user = await userManager.GetUserAsync(context.User);
|
||||
IdentityUser? user = await userManager.GetUserAsync(context.User);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
@@ -99,7 +98,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
|
||||
// Only include personal data for download
|
||||
var personalData = new Dictionary<string, string>();
|
||||
|
||||
IEnumerable<PropertyInfo> personalDataProps = typeof(ApplicationUser).GetProperties()
|
||||
IEnumerable<PropertyInfo> personalDataProps = typeof(IdentityUser).GetProperties()
|
||||
.Where(prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));
|
||||
|
||||
foreach(PropertyInfo p in personalDataProps)
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using Aaru.Server.New.Data;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
|
||||
namespace Aaru.Server.New.Components.Account;
|
||||
|
||||
// Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation.
|
||||
sealed class IdentityNoOpEmailSender : IEmailSender<ApplicationUser>
|
||||
sealed class IdentityNoOpEmailSender : IEmailSender<IdentityUser>
|
||||
{
|
||||
readonly IEmailSender emailSender = new NoOpEmailSender();
|
||||
|
||||
public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink) =>
|
||||
public Task SendConfirmationLinkAsync(IdentityUser user, string email, string confirmationLink) =>
|
||||
emailSender.SendEmailAsync(email,
|
||||
"Confirm your email",
|
||||
$"Please confirm your account by <a href='{confirmationLink}'>clicking here</a>.");
|
||||
|
||||
public Task SendPasswordResetLinkAsync(ApplicationUser user, string email, string resetLink) =>
|
||||
public Task SendPasswordResetLinkAsync(IdentityUser user, string email, string resetLink) =>
|
||||
emailSender.SendEmailAsync(email,
|
||||
"Reset your password",
|
||||
$"Please reset your password by <a href='{resetLink}'>clicking here</a>.");
|
||||
|
||||
public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode) =>
|
||||
public Task SendPasswordResetCodeAsync(IdentityUser user, string email, string resetCode) =>
|
||||
emailSender.SendEmailAsync(email,
|
||||
"Reset your password",
|
||||
$"Please reset your password using the following code: {resetCode}");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Security.Claims;
|
||||
using Aaru.Server.New.Data;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@@ -21,15 +20,14 @@ sealed class IdentityRevalidatingAuthenticationStateProvider
|
||||
// Get the user manager from a new scope to ensure it fetches fresh data
|
||||
await using AsyncServiceScope scope = scopeFactory.CreateAsyncScope();
|
||||
|
||||
UserManager<ApplicationUser> userManager =
|
||||
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
UserManager<IdentityUser> userManager = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
|
||||
|
||||
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
|
||||
}
|
||||
|
||||
async Task<bool> ValidateSecurityStampAsync(UserManager<ApplicationUser> userManager, ClaimsPrincipal principal)
|
||||
async Task<bool> ValidateSecurityStampAsync(UserManager<IdentityUser> userManager, ClaimsPrincipal principal)
|
||||
{
|
||||
ApplicationUser? user = await userManager.GetUserAsync(principal);
|
||||
IdentityUser? user = await userManager.GetUserAsync(principal);
|
||||
|
||||
if(user is null) return false;
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Aaru.Server.New.Data;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Aaru.Server.New.Components.Account;
|
||||
|
||||
sealed class IdentityUserAccessor(UserManager<ApplicationUser> userManager, IdentityRedirectManager redirectManager)
|
||||
sealed class IdentityUserAccessor(UserManager<IdentityUser> userManager, IdentityRedirectManager redirectManager)
|
||||
{
|
||||
public async Task<ApplicationUser> GetRequiredUserAsync(HttpContext context)
|
||||
public async Task<IdentityUser> GetRequiredUserAsync(HttpContext context)
|
||||
{
|
||||
ApplicationUser? user = await userManager.GetUserAsync(context.User);
|
||||
IdentityUser? user = await userManager.GetUserAsync(context.User);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
@page "/Account/ConfirmEmail"
|
||||
@using System.Text
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Confirm email</PageTitle>
|
||||
|
||||
@@ -31,7 +30,7 @@
|
||||
RedirectManager.RedirectTo("");
|
||||
}
|
||||
|
||||
ApplicationUser? user = await UserManager.FindByIdAsync(UserId);
|
||||
IdentityUser? user = await UserManager.FindByIdAsync(UserId);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/ConfirmEmailChange"
|
||||
@using System.Text
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Confirm email change</PageTitle>
|
||||
|
||||
@@ -36,7 +35,7 @@
|
||||
RedirectManager.RedirectToWithStatus("Account/Login", "Error: Invalid email change confirmation link.", HttpContext);
|
||||
}
|
||||
|
||||
ApplicationUser? user = await UserManager.FindByIdAsync(UserId);
|
||||
IdentityUser? user = await UserManager.FindByIdAsync(UserId);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -3,17 +3,16 @@
|
||||
@using System.Security.Claims
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IUserStore<ApplicationUser> UserStore
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ExternalLogin> Logger
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IUserStore<IdentityUser> UserStore
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ExternalLogin> Logger
|
||||
|
||||
<PageTitle>Register</PageTitle>
|
||||
|
||||
@@ -121,8 +120,8 @@
|
||||
|
||||
private async Task OnValidSubmitAsync()
|
||||
{
|
||||
IUserEmailStore<ApplicationUser> emailStore = GetEmailStore();
|
||||
ApplicationUser user = CreateUser();
|
||||
IUserEmailStore<IdentityUser> emailStore = GetEmailStore();
|
||||
IdentityUser user = CreateUser();
|
||||
|
||||
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
|
||||
await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
|
||||
@@ -168,26 +167,26 @@
|
||||
message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}";
|
||||
}
|
||||
|
||||
private ApplicationUser CreateUser()
|
||||
private IdentityUser CreateUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Activator.CreateInstance<ApplicationUser>();
|
||||
return Activator.CreateInstance<IdentityUser>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new InvalidOperationException($"Can't create an instance of '{nameof(ApplicationUser)}'. " + $"Ensure that '{nameof(ApplicationUser)}' is not an abstract class and has a parameterless constructor");
|
||||
throw new InvalidOperationException($"Can't create an instance of '{nameof(IdentityUser)}'. " + $"Ensure that '{nameof(IdentityUser)}' is not an abstract class and has a parameterless constructor");
|
||||
}
|
||||
}
|
||||
|
||||
private IUserEmailStore<ApplicationUser> GetEmailStore()
|
||||
private IUserEmailStore<IdentityUser> GetEmailStore()
|
||||
{
|
||||
if(!UserManager.SupportsUserEmail)
|
||||
{
|
||||
throw new NotSupportedException("The default UI requires a user store with email support.");
|
||||
}
|
||||
|
||||
return (IUserEmailStore<ApplicationUser>)UserStore;
|
||||
return (IUserEmailStore<IdentityUser>)UserStore;
|
||||
}
|
||||
|
||||
private sealed class InputModel
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Forgot your password?</PageTitle>
|
||||
|
||||
@@ -38,7 +37,7 @@
|
||||
|
||||
private async Task OnValidSubmitAsync()
|
||||
{
|
||||
ApplicationUser? user = await UserManager.FindByEmailAsync(Input.Email);
|
||||
IdentityUser? user = await UserManager.FindByEmailAsync(Input.Email);
|
||||
|
||||
if(user is null || !await UserManager.IsEmailConfirmedAsync(user))
|
||||
{
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
@page "/Account/Login"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject ILogger<Login> Logger
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject ILogger<Login> Logger
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Log in</PageTitle>
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/LoginWith2fa"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<LoginWith2fa> Logger
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<LoginWith2fa> Logger
|
||||
|
||||
<PageTitle>Two-factor authentication</PageTitle>
|
||||
|
||||
@@ -44,8 +43,8 @@
|
||||
</p>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
private InputModel Input { get; set; } = new();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
@page "/Account/LoginWithRecoveryCode"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<LoginWithRecoveryCode> Logger
|
||||
|
||||
@@ -33,8 +32,8 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
private InputModel Input { get; set; } = new();
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
@page "/Account/Manage/ChangePassword"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ChangePassword> Logger
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ChangePassword> Logger
|
||||
|
||||
<PageTitle>Change password</PageTitle>
|
||||
|
||||
@@ -39,9 +38,9 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private bool hasPassword;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
private bool hasPassword;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
@page "/Account/Manage/DeletePersonalData"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<DeletePersonalData> Logger
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<DeletePersonalData> Logger
|
||||
|
||||
<PageTitle>Delete Personal Data</PageTitle>
|
||||
|
||||
@@ -38,9 +37,9 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private bool requirePassword;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
private bool requirePassword;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
@page "/Account/Manage/Disable2fa"
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<Disable2fa> Logger
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<Disable2fa> Logger
|
||||
|
||||
<PageTitle>Disable two-factor authentication (2FA)</PageTitle>
|
||||
|
||||
@@ -30,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private ApplicationUser user = default!;
|
||||
private IdentityUser user = default!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>Manage email</PageTitle>
|
||||
|
||||
@@ -53,10 +52,10 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private string? email;
|
||||
private bool isEmailConfirmed;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
private string? email;
|
||||
private bool isEmailConfirmed;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
@using System.Globalization
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject UrlEncoder UrlEncoder
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@@ -70,7 +69,7 @@ else
|
||||
private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
|
||||
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private IdentityUser user = default!;
|
||||
private string? sharedKey;
|
||||
private string? authenticatorUri;
|
||||
private IEnumerable<string>? recoveryCodes;
|
||||
@@ -118,7 +117,7 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask LoadSharedKeyAndQrCodeUriAsync(ApplicationUser user)
|
||||
private async ValueTask LoadSharedKeyAndQrCodeUriAsync(IdentityUser user)
|
||||
{
|
||||
// Load the authenticator key & QR code URI to display on the form
|
||||
string? unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
@page "/Account/Manage/ExternalLogins"
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IUserStore<ApplicationUser> UserStore
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IUserStore<IdentityUser> UserStore
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Manage your external logins</PageTitle>
|
||||
|
||||
@@ -65,7 +64,7 @@
|
||||
@code {
|
||||
public const string LinkLoginCallbackAction = "LinkLoginCallback";
|
||||
|
||||
private ApplicationUser user = default!;
|
||||
private IdentityUser user = default!;
|
||||
private IList<UserLoginInfo>? currentLogins;
|
||||
private IList<AuthenticationScheme>? otherLogins;
|
||||
private bool showRemoveButton;
|
||||
@@ -90,7 +89,7 @@
|
||||
|
||||
string? passwordHash = null;
|
||||
|
||||
if(UserStore is IUserPasswordStore<ApplicationUser> userPasswordStore)
|
||||
if(UserStore is IUserPasswordStore<IdentityUser> userPasswordStore)
|
||||
{
|
||||
passwordHash = await userPasswordStore.GetPasswordHashAsync(user, HttpContext.RequestAborted);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
@page "/Account/Manage/GenerateRecoveryCodes"
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<GenerateRecoveryCodes> Logger
|
||||
@@ -39,7 +38,7 @@ else
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private IdentityUser user = default!;
|
||||
private IEnumerable<string>? recoveryCodes;
|
||||
|
||||
[CascadingParameter]
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/Manage"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Profile</PageTitle>
|
||||
|
||||
@@ -33,9 +32,9 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private ApplicationUser user = default!;
|
||||
private string? username;
|
||||
private string? phoneNumber;
|
||||
private IdentityUser user = default!;
|
||||
private string? username;
|
||||
private string? phoneNumber;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/Manage/ResetAuthenticator"
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ResetAuthenticator> Logger
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject ILogger<ResetAuthenticator> Logger
|
||||
|
||||
<PageTitle>Reset authenticator key</PageTitle>
|
||||
|
||||
@@ -35,7 +34,7 @@
|
||||
|
||||
private async Task OnSubmitAsync()
|
||||
{
|
||||
ApplicationUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
|
||||
IdentityUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
|
||||
await UserManager.SetTwoFactorEnabledAsync(user, false);
|
||||
await UserManager.ResetAuthenticatorKeyAsync(user);
|
||||
string userId = await UserManager.GetUserIdAsync(user);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/Manage/SetPassword"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Set password</PageTitle>
|
||||
|
||||
@@ -37,8 +36,8 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? message;
|
||||
private ApplicationUser user = default!;
|
||||
private string? message;
|
||||
private IdentityUser user = default!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/Manage/TwoFactorAuthentication"
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Http.Features
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityUserAccessor UserAccessor
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Two-factor authentication (2FA)</PageTitle>
|
||||
|
||||
@@ -82,7 +81,7 @@ else
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
ApplicationUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
|
||||
IdentityUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
|
||||
canTrack = HttpContext.Features.Get<ITrackingConsentFeature>()?.CanTrack ?? true;
|
||||
hasAuthenticator = await UserManager.GetAuthenticatorKeyAsync(user) is not null;
|
||||
is2faEnabled = await UserManager.GetTwoFactorEnabledAsync(user);
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IUserStore<ApplicationUser> UserStore
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject ILogger<Register> Logger
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IUserStore<IdentityUser> UserStore
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject ILogger<Register> Logger
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Register</PageTitle>
|
||||
|
||||
@@ -66,10 +65,10 @@
|
||||
|
||||
public async Task RegisterUser(EditContext editContext)
|
||||
{
|
||||
ApplicationUser user = CreateUser();
|
||||
IdentityUser user = CreateUser();
|
||||
|
||||
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
|
||||
IUserEmailStore<ApplicationUser> emailStore = GetEmailStore();
|
||||
IUserEmailStore<IdentityUser> emailStore = GetEmailStore();
|
||||
await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
|
||||
IdentityResult result = await UserManager.CreateAsync(user, Input.Password);
|
||||
|
||||
@@ -110,26 +109,26 @@
|
||||
RedirectManager.RedirectTo(ReturnUrl);
|
||||
}
|
||||
|
||||
private ApplicationUser CreateUser()
|
||||
private IdentityUser CreateUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Activator.CreateInstance<ApplicationUser>();
|
||||
return Activator.CreateInstance<IdentityUser>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new InvalidOperationException($"Can't create an instance of '{nameof(ApplicationUser)}'. " + $"Ensure that '{nameof(ApplicationUser)}' is not an abstract class and has a parameterless constructor.");
|
||||
throw new InvalidOperationException($"Can't create an instance of '{nameof(IdentityUser)}'. " + $"Ensure that '{nameof(IdentityUser)}' is not an abstract class and has a parameterless constructor.");
|
||||
}
|
||||
}
|
||||
|
||||
private IUserEmailStore<ApplicationUser> GetEmailStore()
|
||||
private IUserEmailStore<IdentityUser> GetEmailStore()
|
||||
{
|
||||
if(!UserManager.SupportsUserEmail)
|
||||
{
|
||||
throw new NotSupportedException("The default UI requires a user store with email support.");
|
||||
}
|
||||
|
||||
return (IUserEmailStore<ApplicationUser>)UserStore;
|
||||
return (IUserEmailStore<IdentityUser>)UserStore;
|
||||
}
|
||||
|
||||
private sealed class InputModel
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
@page "/Account/RegisterConfirmation"
|
||||
@using System.Text
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Register confirmation</PageTitle>
|
||||
|
||||
@@ -47,7 +46,7 @@ else
|
||||
RedirectManager.RedirectTo("");
|
||||
}
|
||||
|
||||
ApplicationUser? user = await UserManager.FindByEmailAsync(Email);
|
||||
IdentityUser? user = await UserManager.FindByEmailAsync(Email);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text
|
||||
@using System.Text.Encodings.Web
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IEmailSender<ApplicationUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
@inject IEmailSender<IdentityUser> EmailSender
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Resend email confirmation</PageTitle>
|
||||
|
||||
@@ -40,7 +39,7 @@
|
||||
|
||||
private async Task OnValidSubmitAsync()
|
||||
{
|
||||
ApplicationUser? user = await UserManager.FindByEmailAsync(Input.Email!);
|
||||
IdentityUser? user = await UserManager.FindByEmailAsync(Input.Email!);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/Account/ResetPassword"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Text
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject UserManager<IdentityUser> UserManager
|
||||
|
||||
<PageTitle>Reset password</PageTitle>
|
||||
|
||||
@@ -64,7 +63,7 @@
|
||||
|
||||
private async Task OnValidSubmitAsync()
|
||||
{
|
||||
ApplicationUser? user = await UserManager.FindByEmailAsync(Input.Email);
|
||||
IdentityUser? user = await UserManager.FindByEmailAsync(Input.Email);
|
||||
|
||||
if(user is null)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
@if(externalLogins.Length == 0)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@using Aaru.Server.New.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@inject SignInManager<IdentityUser> SignInManager
|
||||
|
||||
<ul class="flex-column nav nav-pills">
|
||||
<li class="nav-item">
|
||||
|
||||
Reference in New Issue
Block a user