Use proper database context in new server.

This commit is contained in:
2024-05-03 22:54:50 +01:00
parent 7bcaf5b1b0
commit 67cde54e37
38 changed files with 174 additions and 869 deletions

View File

@@ -11,8 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0"/> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.0"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0"/> <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0"/> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0"/> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2"/> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2"/>

View File

@@ -7,10 +7,6 @@
<UserSecretsId>aspnet-Aaru.Server.New-79282495-4F67-4766-871D-448D1338E8BC</UserSecretsId> <UserSecretsId>aspnet-Aaru.Server.New-79282495-4F67-4766-871D-448D1338E8BC</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Update="Data\app.db" CopyToOutputDirectory="PreserveNewest" ExcludeFromSingleFile="true"/>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Markdig" Version="0.37.0"/> <PackageReference Include="Markdig" Version="0.37.0"/>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4"/> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4"/>
@@ -18,6 +14,9 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4"/>
<PackageReference Include="WebStoating.Markdig.PrismWithPlugins" Version="1.0.0"/> <PackageReference Include="WebStoating.Markdig.PrismWithPlugins" Version="1.0.0"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.4"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -3,7 +3,6 @@ using System.Security.Claims;
using System.Text.Json; using System.Text.Json;
using Aaru.Server.New.Components.Account.Pages; using Aaru.Server.New.Components.Account.Pages;
using Aaru.Server.New.Components.Account.Pages.Manage; using Aaru.Server.New.Components.Account.Pages.Manage;
using Aaru.Server.New.Data;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Extensions;
@@ -23,8 +22,8 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
RouteGroupBuilder accountGroup = endpoints.MapGroup("/Account"); RouteGroupBuilder accountGroup = endpoints.MapGroup("/Account");
accountGroup.MapPost("/PerformExternalLogin", accountGroup.MapPost("/PerformExternalLogin",
(HttpContext context, [FromServices] SignInManager<ApplicationUser> signInManager, (HttpContext context, [FromServices] SignInManager<IdentityUser> signInManager,
[FromForm] string provider, [FromForm] string returnUrl) => [FromForm] string provider, [FromForm] string returnUrl) =>
{ {
IEnumerable<KeyValuePair<string, StringValues>> query = IEnumerable<KeyValuePair<string, StringValues>> query =
[ [
@@ -44,7 +43,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
}); });
accountGroup.MapPost("/Logout", accountGroup.MapPost("/Logout",
async (ClaimsPrincipal user, SignInManager<ApplicationUser> signInManager, async (ClaimsPrincipal user, SignInManager<IdentityUser> signInManager,
[FromForm] string returnUrl) => [FromForm] string returnUrl) =>
{ {
await signInManager.SignOutAsync(); await signInManager.SignOutAsync();
@@ -55,7 +54,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
RouteGroupBuilder manageGroup = accountGroup.MapGroup("/Manage").RequireAuthorization(); RouteGroupBuilder manageGroup = accountGroup.MapGroup("/Manage").RequireAuthorization();
manageGroup.MapPost("/LinkExternalLogin", manageGroup.MapPost("/LinkExternalLogin",
async (HttpContext context, [FromServices] SignInManager<ApplicationUser> signInManager, async (HttpContext context, [FromServices] SignInManager<IdentityUser> signInManager,
[FromForm] string provider) => [FromForm] string provider) =>
{ {
// Clear the existing external cookie to ensure a clean login process // Clear the existing external cookie to ensure a clean login process
@@ -79,10 +78,10 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
ILogger downloadLogger = loggerFactory.CreateLogger("DownloadPersonalData"); ILogger downloadLogger = loggerFactory.CreateLogger("DownloadPersonalData");
manageGroup.MapPost("/DownloadPersonalData", manageGroup.MapPost("/DownloadPersonalData",
async (HttpContext context, [FromServices] UserManager<ApplicationUser> userManager, async (HttpContext context, [FromServices] UserManager<IdentityUser> userManager,
[FromServices] AuthenticationStateProvider authenticationStateProvider) => [FromServices] AuthenticationStateProvider authenticationStateProvider) =>
{ {
ApplicationUser? user = await userManager.GetUserAsync(context.User); IdentityUser? user = await userManager.GetUserAsync(context.User);
if(user is null) if(user is null)
{ {
@@ -99,7 +98,7 @@ static class IdentityComponentsEndpointRouteBuilderExtensions
// Only include personal data for download // Only include personal data for download
var personalData = new Dictionary<string, string>(); 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))); .Where(prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));
foreach(PropertyInfo p in personalDataProps) foreach(PropertyInfo p in personalDataProps)

View File

@@ -1,25 +1,24 @@
using Aaru.Server.New.Data;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Identity.UI.Services;
namespace Aaru.Server.New.Components.Account; namespace Aaru.Server.New.Components.Account;
// Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation. // 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(); 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, emailSender.SendEmailAsync(email,
"Confirm your email", "Confirm your email",
$"Please confirm your account by <a href='{confirmationLink}'>clicking here</a>."); $"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, emailSender.SendEmailAsync(email,
"Reset your password", "Reset your password",
$"Please reset your password by <a href='{resetLink}'>clicking here</a>."); $"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, emailSender.SendEmailAsync(email,
"Reset your password", "Reset your password",
$"Please reset your password using the following code: {resetCode}"); $"Please reset your password using the following code: {resetCode}");

View File

@@ -1,5 +1,4 @@
using System.Security.Claims; using System.Security.Claims;
using Aaru.Server.New.Data;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server; using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.Identity; 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 // Get the user manager from a new scope to ensure it fetches fresh data
await using AsyncServiceScope scope = scopeFactory.CreateAsyncScope(); await using AsyncServiceScope scope = scopeFactory.CreateAsyncScope();
UserManager<ApplicationUser> userManager = UserManager<IdentityUser> userManager = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
return await ValidateSecurityStampAsync(userManager, authenticationState.User); 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; if(user is null) return false;

View File

@@ -1,13 +1,12 @@
using Aaru.Server.New.Data;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
namespace Aaru.Server.New.Components.Account; 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) if(user is null)
{ {

View File

@@ -1,11 +1,10 @@
@page "/Account/ConfirmEmail" @page "/Account/ConfirmEmail"
@using System.Text @using System.Text
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Confirm email</PageTitle> <PageTitle>Confirm email</PageTitle>
@@ -31,7 +30,7 @@
RedirectManager.RedirectTo(""); RedirectManager.RedirectTo("");
} }
ApplicationUser? user = await UserManager.FindByIdAsync(UserId); IdentityUser? user = await UserManager.FindByIdAsync(UserId);
if(user is null) if(user is null)
{ {

View File

@@ -1,12 +1,11 @@
@page "/Account/ConfirmEmailChange" @page "/Account/ConfirmEmailChange"
@using System.Text @using System.Text
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Confirm email change</PageTitle> <PageTitle>Confirm email change</PageTitle>
@@ -36,7 +35,7 @@
RedirectManager.RedirectToWithStatus("Account/Login", "Error: Invalid email change confirmation link.", HttpContext); 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) if(user is null)
{ {

View File

@@ -3,17 +3,16 @@
@using System.Security.Claims @using System.Security.Claims
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IUserStore<ApplicationUser> UserStore @inject IUserStore<IdentityUser> UserStore
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<ExternalLogin> Logger @inject ILogger<ExternalLogin> Logger
<PageTitle>Register</PageTitle> <PageTitle>Register</PageTitle>
@@ -121,8 +120,8 @@
private async Task OnValidSubmitAsync() private async Task OnValidSubmitAsync()
{ {
IUserEmailStore<ApplicationUser> emailStore = GetEmailStore(); IUserEmailStore<IdentityUser> emailStore = GetEmailStore();
ApplicationUser user = CreateUser(); IdentityUser user = CreateUser();
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
await emailStore.SetEmailAsync(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))}"; message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}";
} }
private ApplicationUser CreateUser() private IdentityUser CreateUser()
{ {
try try
{ {
return Activator.CreateInstance<ApplicationUser>(); return Activator.CreateInstance<IdentityUser>();
} }
catch 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) if(!UserManager.SupportsUserEmail)
{ {
throw new NotSupportedException("The default UI requires a user store with email support."); 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 private sealed class InputModel

View File

@@ -2,14 +2,13 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Forgot your password?</PageTitle> <PageTitle>Forgot your password?</PageTitle>
@@ -38,7 +37,7 @@
private async Task OnValidSubmitAsync() 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)) if(user is null || !await UserManager.IsEmailConfirmedAsync(user))
{ {

View File

@@ -1,13 +1,12 @@
@page "/Account/Login" @page "/Account/Login"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject ILogger<Login> Logger @inject ILogger<Login> Logger
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Log in</PageTitle> <PageTitle>Log in</PageTitle>

View File

@@ -1,12 +1,11 @@
@page "/Account/LoginWith2fa" @page "/Account/LoginWith2fa"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<LoginWith2fa> Logger @inject ILogger<LoginWith2fa> Logger
<PageTitle>Two-factor authentication</PageTitle> <PageTitle>Two-factor authentication</PageTitle>
@@ -44,8 +43,8 @@
</p> </p>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
[SupplyParameterFromForm] [SupplyParameterFromForm]
private InputModel Input { get; set; } = new(); private InputModel Input { get; set; } = new();

View File

@@ -1,10 +1,9 @@
@page "/Account/LoginWithRecoveryCode" @page "/Account/LoginWithRecoveryCode"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<LoginWithRecoveryCode> Logger @inject ILogger<LoginWithRecoveryCode> Logger
@@ -33,8 +32,8 @@
</div> </div>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
[SupplyParameterFromForm] [SupplyParameterFromForm]
private InputModel Input { get; set; } = new(); private InputModel Input { get; set; } = new();

View File

@@ -1,13 +1,12 @@
@page "/Account/Manage/ChangePassword" @page "/Account/Manage/ChangePassword"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<ChangePassword> Logger @inject ILogger<ChangePassword> Logger
<PageTitle>Change password</PageTitle> <PageTitle>Change password</PageTitle>
@@ -39,9 +38,9 @@
</div> </div>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
private bool hasPassword; private bool hasPassword;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -1,13 +1,12 @@
@page "/Account/Manage/DeletePersonalData" @page "/Account/Manage/DeletePersonalData"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<DeletePersonalData> Logger @inject ILogger<DeletePersonalData> Logger
<PageTitle>Delete Personal Data</PageTitle> <PageTitle>Delete Personal Data</PageTitle>
@@ -38,9 +37,9 @@
</div> </div>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
private bool requirePassword; private bool requirePassword;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -1,11 +1,10 @@
@page "/Account/Manage/Disable2fa" @page "/Account/Manage/Disable2fa"
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<Disable2fa> Logger @inject ILogger<Disable2fa> Logger
<PageTitle>Disable two-factor authentication (2FA)</PageTitle> <PageTitle>Disable two-factor authentication (2FA)</PageTitle>
@@ -30,7 +29,7 @@
</div> </div>
@code { @code {
private ApplicationUser user = default!; private IdentityUser user = default!;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -2,14 +2,13 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<PageTitle>Manage email</PageTitle> <PageTitle>Manage email</PageTitle>
@@ -53,10 +52,10 @@
</div> </div>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
private string? email; private string? email;
private bool isEmailConfirmed; private bool isEmailConfirmed;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -3,10 +3,9 @@
@using System.Globalization @using System.Globalization
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject UrlEncoder UrlEncoder @inject UrlEncoder UrlEncoder
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@@ -70,7 +69,7 @@ else
private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6"; private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
private string? sharedKey; private string? sharedKey;
private string? authenticatorUri; private string? authenticatorUri;
private IEnumerable<string>? recoveryCodes; 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 // Load the authenticator key & QR code URI to display on the form
string? unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user); string? unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user);

View File

@@ -1,13 +1,12 @@
@page "/Account/Manage/ExternalLogins" @page "/Account/Manage/ExternalLogins"
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IUserStore<ApplicationUser> UserStore @inject IUserStore<IdentityUser> UserStore
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Manage your external logins</PageTitle> <PageTitle>Manage your external logins</PageTitle>
@@ -65,7 +64,7 @@
@code { @code {
public const string LinkLoginCallbackAction = "LinkLoginCallback"; public const string LinkLoginCallbackAction = "LinkLoginCallback";
private ApplicationUser user = default!; private IdentityUser user = default!;
private IList<UserLoginInfo>? currentLogins; private IList<UserLoginInfo>? currentLogins;
private IList<AuthenticationScheme>? otherLogins; private IList<AuthenticationScheme>? otherLogins;
private bool showRemoveButton; private bool showRemoveButton;
@@ -90,7 +89,7 @@
string? passwordHash = null; string? passwordHash = null;
if(UserStore is IUserPasswordStore<ApplicationUser> userPasswordStore) if(UserStore is IUserPasswordStore<IdentityUser> userPasswordStore)
{ {
passwordHash = await userPasswordStore.GetPasswordHashAsync(user, HttpContext.RequestAborted); passwordHash = await userPasswordStore.GetPasswordHashAsync(user, HttpContext.RequestAborted);
} }

View File

@@ -1,8 +1,7 @@
@page "/Account/Manage/GenerateRecoveryCodes" @page "/Account/Manage/GenerateRecoveryCodes"
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<GenerateRecoveryCodes> Logger @inject ILogger<GenerateRecoveryCodes> Logger
@@ -39,7 +38,7 @@ else
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
private IEnumerable<string>? recoveryCodes; private IEnumerable<string>? recoveryCodes;
[CascadingParameter] [CascadingParameter]

View File

@@ -1,12 +1,11 @@
@page "/Account/Manage" @page "/Account/Manage"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Profile</PageTitle> <PageTitle>Profile</PageTitle>
@@ -33,9 +32,9 @@
</div> </div>
@code { @code {
private ApplicationUser user = default!; private IdentityUser user = default!;
private string? username; private string? username;
private string? phoneNumber; private string? phoneNumber;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -1,12 +1,11 @@
@page "/Account/Manage/ResetAuthenticator" @page "/Account/Manage/ResetAuthenticator"
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject ILogger<ResetAuthenticator> Logger @inject ILogger<ResetAuthenticator> Logger
<PageTitle>Reset authenticator key</PageTitle> <PageTitle>Reset authenticator key</PageTitle>
@@ -35,7 +34,7 @@
private async Task OnSubmitAsync() private async Task OnSubmitAsync()
{ {
ApplicationUser user = await UserAccessor.GetRequiredUserAsync(HttpContext); IdentityUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
await UserManager.SetTwoFactorEnabledAsync(user, false); await UserManager.SetTwoFactorEnabledAsync(user, false);
await UserManager.ResetAuthenticatorKeyAsync(user); await UserManager.ResetAuthenticatorKeyAsync(user);
string userId = await UserManager.GetUserIdAsync(user); string userId = await UserManager.GetUserIdAsync(user);

View File

@@ -1,12 +1,11 @@
@page "/Account/Manage/SetPassword" @page "/Account/Manage/SetPassword"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Set password</PageTitle> <PageTitle>Set password</PageTitle>
@@ -37,8 +36,8 @@
</div> </div>
@code { @code {
private string? message; private string? message;
private ApplicationUser user = default!; private IdentityUser user = default!;
[CascadingParameter] [CascadingParameter]
private HttpContext HttpContext { get; set; } = default!; private HttpContext HttpContext { get; set; } = default!;

View File

@@ -1,12 +1,11 @@
@page "/Account/Manage/TwoFactorAuthentication" @page "/Account/Manage/TwoFactorAuthentication"
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Http.Features @using Microsoft.AspNetCore.Http.Features
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityUserAccessor UserAccessor @inject IdentityUserAccessor UserAccessor
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Two-factor authentication (2FA)</PageTitle> <PageTitle>Two-factor authentication (2FA)</PageTitle>
@@ -82,7 +81,7 @@ else
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
ApplicationUser user = await UserAccessor.GetRequiredUserAsync(HttpContext); IdentityUser user = await UserAccessor.GetRequiredUserAsync(HttpContext);
canTrack = HttpContext.Features.Get<ITrackingConsentFeature>()?.CanTrack ?? true; canTrack = HttpContext.Features.Get<ITrackingConsentFeature>()?.CanTrack ?? true;
hasAuthenticator = await UserManager.GetAuthenticatorKeyAsync(user) is not null; hasAuthenticator = await UserManager.GetAuthenticatorKeyAsync(user) is not null;
is2faEnabled = await UserManager.GetTwoFactorEnabledAsync(user); is2faEnabled = await UserManager.GetTwoFactorEnabledAsync(user);

View File

@@ -2,17 +2,16 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IUserStore<ApplicationUser> UserStore @inject IUserStore<IdentityUser> UserStore
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject ILogger<Register> Logger @inject ILogger<Register> Logger
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Register</PageTitle> <PageTitle>Register</PageTitle>
@@ -66,10 +65,10 @@
public async Task RegisterUser(EditContext editContext) public async Task RegisterUser(EditContext editContext)
{ {
ApplicationUser user = CreateUser(); IdentityUser user = CreateUser();
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
IUserEmailStore<ApplicationUser> emailStore = GetEmailStore(); IUserEmailStore<IdentityUser> emailStore = GetEmailStore();
await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
IdentityResult result = await UserManager.CreateAsync(user, Input.Password); IdentityResult result = await UserManager.CreateAsync(user, Input.Password);
@@ -110,26 +109,26 @@
RedirectManager.RedirectTo(ReturnUrl); RedirectManager.RedirectTo(ReturnUrl);
} }
private ApplicationUser CreateUser() private IdentityUser CreateUser()
{ {
try try
{ {
return Activator.CreateInstance<ApplicationUser>(); return Activator.CreateInstance<IdentityUser>();
} }
catch 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) if(!UserManager.SupportsUserEmail)
{ {
throw new NotSupportedException("The default UI requires a user store with email support."); 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 private sealed class InputModel

View File

@@ -1,13 +1,12 @@
@page "/Account/RegisterConfirmation" @page "/Account/RegisterConfirmation"
@using System.Text @using System.Text
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Register confirmation</PageTitle> <PageTitle>Register confirmation</PageTitle>
@@ -47,7 +46,7 @@ else
RedirectManager.RedirectTo(""); RedirectManager.RedirectTo("");
} }
ApplicationUser? user = await UserManager.FindByEmailAsync(Email); IdentityUser? user = await UserManager.FindByEmailAsync(Email);
if(user is null) if(user is null)
{ {

View File

@@ -2,14 +2,13 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using System.Text @using System.Text
@using System.Text.Encodings.Web @using System.Text.Encodings.Web
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender @inject IEmailSender<IdentityUser> EmailSender
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Resend email confirmation</PageTitle> <PageTitle>Resend email confirmation</PageTitle>
@@ -40,7 +39,7 @@
private async Task OnValidSubmitAsync() private async Task OnValidSubmitAsync()
{ {
ApplicationUser? user = await UserManager.FindByEmailAsync(Input.Email!); IdentityUser? user = await UserManager.FindByEmailAsync(Input.Email!);
if(user is null) if(user is null)
{ {

View File

@@ -1,12 +1,11 @@
@page "/Account/ResetPassword" @page "/Account/ResetPassword"
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using System.Text @using System.Text
@using Aaru.Server.New.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities @using Microsoft.AspNetCore.WebUtilities
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@inject UserManager<ApplicationUser> UserManager @inject UserManager<IdentityUser> UserManager
<PageTitle>Reset password</PageTitle> <PageTitle>Reset password</PageTitle>
@@ -64,7 +63,7 @@
private async Task OnValidSubmitAsync() private async Task OnValidSubmitAsync()
{ {
ApplicationUser? user = await UserManager.FindByEmailAsync(Input.Email); IdentityUser? user = await UserManager.FindByEmailAsync(Input.Email);
if(user is null) if(user is null)
{ {

View File

@@ -1,8 +1,7 @@
@using Aaru.Server.New.Data @using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<IdentityUser> SignInManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
@if(externalLogins.Length == 0) @if(externalLogins.Length == 0)
{ {

View File

@@ -1,6 +1,5 @@
@using Aaru.Server.New.Data @using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Identity @inject SignInManager<IdentityUser> SignInManager
@inject SignInManager<ApplicationUser> SignInManager
<ul class="flex-column nav nav-pills"> <ul class="flex-column nav nav-pills">
<li class="nav-item"> <li class="nav-item">

View File

@@ -1,7 +0,0 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Aaru.Server.New.Data;
public class ApplicationDbContext
(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options) {}

View File

@@ -1,6 +0,0 @@
using Microsoft.AspNetCore.Identity;
namespace Aaru.Server.New.Data;
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser {}

View File

@@ -1,226 +0,0 @@
// <auto-generated />
using System;
using Aaru.Server.New.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Aaru.Server.New.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("00000000000000_CreateIdentitySchema")]
partial class CreateIdentitySchema
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
modelBuilder.Entity("Aaru.Server.New.Data.ApplicationUser",
b =>
{
b.Property<string>("Id").HasColumnType("TEXT");
b.Property<int>("AccessFailedCount").HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp").IsConcurrencyToken().HasColumnType("TEXT");
b.Property<string>("Email").HasMaxLength(256).HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled").HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd").HasColumnType("TEXT");
b.Property<string>("NormalizedEmail").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("NormalizedUserName").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("PasswordHash").HasColumnType("TEXT");
b.Property<string>("PhoneNumber").HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed").HasColumnType("INTEGER");
b.Property<string>("SecurityStamp").HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled").HasColumnType("INTEGER");
b.Property<string>("UserName").HasMaxLength(256).HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail").HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName").IsUnique().HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole",
b =>
{
b.Property<string>("Id").HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp").IsConcurrencyToken().HasColumnType("TEXT");
b.Property<string>("Name").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("NormalizedName").HasMaxLength(256).HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName").IsUnique().HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>",
b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<string>("ClaimType").HasColumnType("TEXT");
b.Property<string>("ClaimValue").HasColumnType("TEXT");
b.Property<string>("RoleId").IsRequired().HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>",
b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<string>("ClaimType").HasColumnType("TEXT");
b.Property<string>("ClaimValue").HasColumnType("TEXT");
b.Property<string>("UserId").IsRequired().HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>",
b =>
{
b.Property<string>("LoginProvider").HasColumnType("TEXT");
b.Property<string>("ProviderKey").HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName").HasColumnType("TEXT");
b.Property<string>("UserId").IsRequired().HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>",
b =>
{
b.Property<string>("UserId").HasColumnType("TEXT");
b.Property<string>("RoleId").HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>",
b =>
{
b.Property<string>("UserId").HasColumnType("TEXT");
b.Property<string>("LoginProvider").HasColumnType("TEXT");
b.Property<string>("Name").HasColumnType("TEXT");
b.Property<string>("Value").HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>",
b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>",
b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,212 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Aaru.Server.New.Migrations
{
/// <inheritdoc />
public partial class CreateIdentitySchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
NormalizedName =
table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table => { table.PrimaryKey("PK_AspNetRoles", x => x.Id); });
migrationBuilder.CreateTable(name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
UserName =
table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
NormalizedUserName =
table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
NormalizedEmail =
table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "INTEGER", nullable: false),
PasswordHash = table.Column<string>(type: "TEXT", nullable: true),
SecurityStamp = table.Column<string>(type: "TEXT", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "TEXT", nullable: true),
PhoneNumber = table.Column<string>(type: "TEXT", nullable: true),
PhoneNumberConfirmed =
table.Column<bool>(type: "INTEGER", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "TEXT", nullable: true),
LockoutEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
AccessFailedCount = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table => { table.PrimaryKey("PK_AspNetUsers", x => x.Id); });
migrationBuilder.CreateTable(name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
RoleId = table.Column<string>(type: "TEXT", nullable: false),
ClaimType = table.Column<string>(type: "TEXT", nullable: true),
ClaimValue = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserId = table.Column<string>(type: "TEXT", nullable: false),
ClaimType = table.Column<string>(type: "TEXT", nullable: true),
ClaimValue = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "TEXT", nullable: false),
ProviderKey = table.Column<string>(type: "TEXT", nullable: false),
ProviderDisplayName = table.Column<string>(type: "TEXT", nullable: true),
UserId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins",
x => new
{
x.LoginProvider,
x.ProviderKey
});
table.ForeignKey(name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "TEXT", nullable: false),
RoleId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles",
x => new
{
x.UserId,
x.RoleId
});
table.ForeignKey(name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "TEXT", nullable: false),
LoginProvider = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Value = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens",
x => new
{
x.UserId,
x.LoginProvider,
x.Name
});
table.ForeignKey(name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(name: "IX_AspNetUserRoles_RoleId", table: "AspNetUserRoles", column: "RoleId");
migrationBuilder.CreateIndex(name: "EmailIndex", table: "AspNetUsers", column: "NormalizedEmail");
migrationBuilder.CreateIndex(name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: "AspNetRoleClaims");
migrationBuilder.DropTable(name: "AspNetUserClaims");
migrationBuilder.DropTable(name: "AspNetUserLogins");
migrationBuilder.DropTable(name: "AspNetUserRoles");
migrationBuilder.DropTable(name: "AspNetUserTokens");
migrationBuilder.DropTable(name: "AspNetRoles");
migrationBuilder.DropTable(name: "AspNetUsers");
}
}
}

View File

@@ -1,223 +0,0 @@
// <auto-generated />
using System;
using Aaru.Server.New.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Aaru.Server.New.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
modelBuilder.Entity("Aaru.Server.New.Data.ApplicationUser",
b =>
{
b.Property<string>("Id").HasColumnType("TEXT");
b.Property<int>("AccessFailedCount").HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp").IsConcurrencyToken().HasColumnType("TEXT");
b.Property<string>("Email").HasMaxLength(256).HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled").HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd").HasColumnType("TEXT");
b.Property<string>("NormalizedEmail").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("NormalizedUserName").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("PasswordHash").HasColumnType("TEXT");
b.Property<string>("PhoneNumber").HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed").HasColumnType("INTEGER");
b.Property<string>("SecurityStamp").HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled").HasColumnType("INTEGER");
b.Property<string>("UserName").HasMaxLength(256).HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail").HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName").IsUnique().HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole",
b =>
{
b.Property<string>("Id").HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp").IsConcurrencyToken().HasColumnType("TEXT");
b.Property<string>("Name").HasMaxLength(256).HasColumnType("TEXT");
b.Property<string>("NormalizedName").HasMaxLength(256).HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName").IsUnique().HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>",
b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<string>("ClaimType").HasColumnType("TEXT");
b.Property<string>("ClaimValue").HasColumnType("TEXT");
b.Property<string>("RoleId").IsRequired().HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>",
b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<string>("ClaimType").HasColumnType("TEXT");
b.Property<string>("ClaimValue").HasColumnType("TEXT");
b.Property<string>("UserId").IsRequired().HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>",
b =>
{
b.Property<string>("LoginProvider").HasColumnType("TEXT");
b.Property<string>("ProviderKey").HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName").HasColumnType("TEXT");
b.Property<string>("UserId").IsRequired().HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>",
b =>
{
b.Property<string>("UserId").HasColumnType("TEXT");
b.Property<string>("RoleId").HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>",
b =>
{
b.Property<string>("UserId").HasColumnType("TEXT");
b.Property<string>("LoginProvider").HasColumnType("TEXT");
b.Property<string>("Name").HasColumnType("TEXT");
b.Property<string>("Value").HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>",
b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>",
b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>",
b =>
{
b.HasOne("Aaru.Server.New.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

Binary file not shown.

View File

@@ -1,6 +1,5 @@
using Aaru.Server.New.Components; using Aaru.Server.New.Components;
using Aaru.Server.New.Components.Account; using Aaru.Server.New.Components.Account;
using Aaru.Server.New.Data;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -25,15 +24,23 @@ builder.Services.AddAuthentication(options =>
string connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? string connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ??
throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(connectionString)); builder.Services.AddDbContext<DbContext>(options => options
.UseMySql(connectionString,
new MariaDbServerVersion(new Version(10, 4, 0)))
.UseLazyLoadingProxies());
builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true) builder.Services.AddIdentityCore<IdentityUser>(options =>
.AddEntityFrameworkStores<ApplicationDbContext>() {
options.SignIn.RequireConfirmedAccount = true;
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<DbContext>()
.AddSignInManager() .AddSignInManager()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>(); builder.Services.AddSingleton<IEmailSender<IdentityUser>, IdentityNoOpEmailSender>();
WebApplication app = builder.Build(); WebApplication app = builder.Build();

View File

@@ -1,5 +1,8 @@
{ {
"Logging": { "ConnectionStrings": {
"DefaultConnection": "server=mariadb-dev.claunia.com;port=3306;database=discimagechef;uid=dic;password=dicpass"
},
"Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"