Renamed ApplicationDbContext to IdentityDbContext
This commit is contained in:
@@ -19,7 +19,7 @@ public static class DependencyInjection
|
|||||||
services.AddHttpContextAccessor();
|
services.AddHttpContextAccessor();
|
||||||
|
|
||||||
services.AddHealthChecks()
|
services.AddHealthChecks()
|
||||||
.AddDbContextCheck<ApplicationDbContext>();
|
.AddDbContextCheck<IdentityDbContext>();
|
||||||
|
|
||||||
services.AddRazorPages();
|
services.AddRazorPages();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users;
|
|
||||||
|
|
||||||
public class ApplicationRole : IdentityRole<Guid>
|
|
||||||
{
|
|
||||||
public ApplicationRole() { }
|
|
||||||
public ApplicationRole(string roleName) : base(roleName) { }
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Data
|
namespace Hutopy.Web.Features.Users.Data
|
||||||
{
|
{
|
||||||
public class ApplicationDbContext(
|
public class IdentityDbContext(
|
||||||
DbContextOptions<ApplicationDbContext> options)
|
DbContextOptions<IdentityDbContext> options)
|
||||||
: IdentityDbContext<ApplicationUser, ApplicationRole, Guid>(options)
|
: IdentityDbContext<IdentityUser, IdentityRole, Guid>(options)
|
||||||
{
|
{
|
||||||
public const string SchemaName = "Identity";
|
public const string SchemaName = "Identity";
|
||||||
protected override void OnModelCreating(ModelBuilder
|
protected override void OnModelCreating(ModelBuilder
|
||||||
@@ -4,11 +4,11 @@ namespace Hutopy.Web.Features.Users.Data;
|
|||||||
|
|
||||||
public static class InitializerExtensions
|
public static class InitializerExtensions
|
||||||
{
|
{
|
||||||
public static async Task InitialiseApplicationDatabaseAsync(this WebApplication app)
|
public static async Task InitialiseIdentityDatabaseAsync(this WebApplication app)
|
||||||
{
|
{
|
||||||
using var scope = app.Services.CreateScope();
|
using var scope = app.Services.CreateScope();
|
||||||
|
|
||||||
var initializer = scope.ServiceProvider.GetRequiredService<ApplicationDbContextInitializer>();
|
var initializer = scope.ServiceProvider.GetRequiredService<IdentityDbContextInitializer>();
|
||||||
|
|
||||||
await initializer.InitialiseAsync();
|
await initializer.InitialiseAsync();
|
||||||
|
|
||||||
@@ -16,10 +16,10 @@ public static class InitializerExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ApplicationDbContextInitializer(
|
public class IdentityDbContextInitializer(
|
||||||
ILogger<ApplicationDbContextInitializer> logger,
|
ILogger<IdentityDbContextInitializer> logger,
|
||||||
ApplicationDbContext context,
|
IdentityDbContext context,
|
||||||
RoleManager<ApplicationRole> roleManager)
|
RoleManager<IdentityRole> roleManager)
|
||||||
{
|
{
|
||||||
public async Task InitialiseAsync()
|
public async Task InitialiseAsync()
|
||||||
{
|
{
|
||||||
@@ -49,13 +49,13 @@ public class ApplicationDbContextInitializer(
|
|||||||
|
|
||||||
private async Task TrySeedAsync()
|
private async Task TrySeedAsync()
|
||||||
{
|
{
|
||||||
var administratorRole = new ApplicationRole(KnownRoles.Administrator);
|
var administratorRole = new IdentityRole(KnownRoles.Administrator);
|
||||||
if (roleManager.Roles.All(r => r.Name != administratorRole.Name))
|
if (roleManager.Roles.All(r => r.Name != administratorRole.Name))
|
||||||
{
|
{
|
||||||
await roleManager.CreateAsync(administratorRole);
|
await roleManager.CreateAsync(administratorRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
var roleCreator = new ApplicationRole(KnownRoles.Creator);
|
var roleCreator = new IdentityRole(KnownRoles.Creator);
|
||||||
if (roleManager.Roles.All(r => r.Name != roleCreator.Name))
|
if (roleManager.Roles.All(r => r.Name != roleCreator.Name))
|
||||||
{
|
{
|
||||||
await roleManager.CreateAsync(roleCreator);
|
await roleManager.CreateAsync(roleCreator);
|
||||||
@@ -11,7 +11,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Data.Migrations
|
namespace Hutopy.Web.Features.Users.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
[DbContext(typeof(IdentityDbContext))]
|
||||||
[Migration("20241020183421_Initial")]
|
[Migration("20241020183421_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Hutopy.Web.Features.Users.ApplicationRole", b =>
|
modelBuilder.Entity("Hutopy.Web.Features.Users.IdentityRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -53,7 +53,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
b.ToTable("AspNetRoles", "Identity");
|
b.ToTable("AspNetRoles", "Identity");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Hutopy.Web.Features.Users.ApplicationUser", b =>
|
modelBuilder.Entity("Hutopy.Web.Features.Users.IdentityUser", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -250,7 +250,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationRole", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityRole", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("RoleId")
|
.HasForeignKey("RoleId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -259,7 +259,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -268,7 +268,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -277,13 +277,13 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationRole", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityRole", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("RoleId")
|
.HasForeignKey("RoleId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -292,7 +292,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Data.Migrations
|
namespace Hutopy.Web.Features.Users.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
[DbContext(typeof(IdentityDbContext))]
|
||||||
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
@@ -23,7 +23,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Hutopy.Web.Features.Users.ApplicationRole", b =>
|
modelBuilder.Entity("Hutopy.Web.Features.Users.IdentityRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -50,7 +50,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
b.ToTable("AspNetRoles", "Identity");
|
b.ToTable("AspNetRoles", "Identity");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Hutopy.Web.Features.Users.ApplicationUser", b =>
|
modelBuilder.Entity("Hutopy.Web.Features.Users.IdentityUser", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -247,7 +247,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationRole", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityRole", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("RoleId")
|
.HasForeignKey("RoleId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -256,7 +256,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -265,7 +265,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -274,13 +274,13 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationRole", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityRole", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("RoleId")
|
.HasForeignKey("RoleId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -289,7 +289,7 @@ namespace Hutopy.Web.Features.Users.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Hutopy.Web.Features.Users.ApplicationUser", null)
|
b.HasOne("Hutopy.Web.Features.Users.IdentityUser", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public static class DependencyInjection
|
|||||||
services.AddDbContext<MessagingDbContext>(configureAction);
|
services.AddDbContext<MessagingDbContext>(configureAction);
|
||||||
services.AddScoped<MessagingDbContextInitializer>();
|
services.AddScoped<MessagingDbContextInitializer>();
|
||||||
|
|
||||||
services.AddDbContext<ApplicationDbContext>(configureAction);
|
services.AddDbContext<IdentityDbContext>(configureAction);
|
||||||
services.AddScoped<ApplicationDbContextInitializer>();
|
services.AddScoped<IdentityDbContextInitializer>();
|
||||||
|
|
||||||
services.AddAuthentication()
|
services.AddAuthentication()
|
||||||
.AddBearerToken(IdentityConstants.BearerScheme);
|
.AddBearerToken(IdentityConstants.BearerScheme);
|
||||||
@@ -23,12 +23,12 @@ public static class DependencyInjection
|
|||||||
services.AddAuthorizationBuilder();
|
services.AddAuthorizationBuilder();
|
||||||
|
|
||||||
services
|
services
|
||||||
.AddIdentityCore<ApplicationUser>()
|
.AddIdentityCore<IdentityUser>()
|
||||||
.AddUserManager<ApplicationUserManager>()
|
.AddUserManager<IdentityUserManager>()
|
||||||
.AddRoles<ApplicationRole>()
|
.AddRoles<IdentityRole>()
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
.AddEntityFrameworkStores<IdentityDbContext>()
|
||||||
.AddApiEndpoints()
|
.AddApiEndpoints()
|
||||||
.AddSignInManager<SignInManager<ApplicationUser>>()
|
.AddSignInManager<SignInManager<IdentityUser>>()
|
||||||
.AddDefaultTokenProviders();
|
.AddDefaultTokenProviders();
|
||||||
|
|
||||||
// Singleton services
|
// Singleton services
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ public record ChangeAddressRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangeAddressHandler(
|
public class ChangeAddressHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangeAddressRequest>
|
: Endpoint<ChangeAddressRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ public record ChangeAliasRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangeAliasHandler(
|
public class ChangeAliasHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangeAliasRequest>
|
: Endpoint<ChangeAliasRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ public record ChangeBirthDateRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangeBirthDateHandler(
|
public class ChangeBirthDateHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangeBirthDateRequest>
|
: Endpoint<ChangeBirthDateRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ public record ChangeEmailRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangeEmailHandler(
|
public class ChangeEmailHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangeEmailRequest>
|
: Endpoint<ChangeEmailRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ public record ChangeFullnameRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangeFullnameHandler(
|
public class ChangeFullnameHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangeFullnameRequest>
|
: Endpoint<ChangeFullnameRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.Security;
|
||||||
using Hutopy.Web.Common.Security;
|
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ public record ChangePhoneRequest(
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangePhoneHandler(
|
public class ChangePhoneHandler(
|
||||||
ApplicationUserManager userManager)
|
IdentityUserManager userManager)
|
||||||
: Endpoint<ChangePhoneRequest>
|
: Endpoint<ChangePhoneRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Hutopy.Web.Common;
|
using Hutopy.Web.Common.BlobStorage;
|
||||||
using Hutopy.Web.Common.BlobStorage;
|
|
||||||
using Hutopy.Web.Common.Security;
|
using Hutopy.Web.Common.Security;
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Users.Handlers;
|
namespace Hutopy.Web.Features.Users.Handlers;
|
||||||
@@ -25,7 +24,7 @@ public sealed class ChangePortraitRequestValidator : Validator<ChangePortraitReq
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class ChangePortraitHandler(
|
public class ChangePortraitHandler(
|
||||||
ApplicationUserManager userManager,
|
IdentityUserManager userManager,
|
||||||
AzureBlobStorage blobStorage)
|
AzureBlobStorage blobStorage)
|
||||||
: Endpoint<ChangePortraitRequest, ChangePortraitResponse>
|
: Endpoint<ChangePortraitRequest, ChangePortraitResponse>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ public record LoginWithGoogleResponse(
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class LoginWithGoogleHandler(
|
public class LoginWithGoogleHandler(
|
||||||
IHttpClientFactory httpClientFactory,
|
IHttpClientFactory httpClientFactory,
|
||||||
ApplicationUserManager userManager,
|
IdentityUserManager userManager,
|
||||||
SignInManager<ApplicationUser> signInManager,
|
SignInManager<IdentityUser> signInManager,
|
||||||
IOptionsSnapshot<JwtOptions> jwtOptions)
|
IOptionsSnapshot<JwtOptions> jwtOptions)
|
||||||
: Endpoint<LoginWithGoogleRequest, LoginWithGoogleResponse>
|
: Endpoint<LoginWithGoogleRequest, LoginWithGoogleResponse>
|
||||||
{
|
{
|
||||||
@@ -91,7 +91,7 @@ public class LoginWithGoogleHandler(
|
|||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
var generatedPassword = PasswordGenerator.GeneratePassword(10, 12);
|
var generatedPassword = PasswordGenerator.GeneratePassword(10, 12);
|
||||||
var generatedUser = new ApplicationUser
|
var generatedUser = new IdentityUser
|
||||||
{
|
{
|
||||||
UserName = userInfo.Email,
|
UserName = userInfo.Email,
|
||||||
Email = userInfo.Email,
|
Email = userInfo.Email,
|
||||||
|
|||||||
9
src/Web/Features/Users/IdentityRole.cs
Normal file
9
src/Web/Features/Users/IdentityRole.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Features.Users;
|
||||||
|
|
||||||
|
public class IdentityRole : IdentityRole<Guid>
|
||||||
|
{
|
||||||
|
public IdentityRole() { }
|
||||||
|
public IdentityRole(string roleName) : base(roleName) { }
|
||||||
|
}
|
||||||
@@ -4,14 +4,14 @@ using Hutopy.Web.Features.Users.Models;
|
|||||||
namespace Hutopy.Web.Features.Users;
|
namespace Hutopy.Web.Features.Users;
|
||||||
|
|
||||||
public class IdentityService(
|
public class IdentityService(
|
||||||
ApplicationUserManager userManager,
|
IdentityUserManager userManager,
|
||||||
IHttpContextAccessor contextAccessor
|
IHttpContextAccessor contextAccessor
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
public async Task<Result<Guid>> CreateUserAsync(string email, string userName, string firstName, string lastName,
|
public async Task<Result<Guid>> CreateUserAsync(string email, string userName, string firstName, string lastName,
|
||||||
string password)
|
string password)
|
||||||
{
|
{
|
||||||
var applicationUser = new ApplicationUser
|
var applicationUser = new IdentityUser
|
||||||
{
|
{
|
||||||
UserName = userName, Email = email, Firstname = firstName, Lastname = lastName
|
UserName = userName, Email = email, Firstname = firstName, Lastname = lastName
|
||||||
};
|
};
|
||||||
@@ -28,7 +28,7 @@ public class IdentityService(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UserModel BuildModelFrom(ApplicationUser response)
|
private static UserModel BuildModelFrom(IdentityUser response)
|
||||||
{
|
{
|
||||||
var userModel = new UserModel
|
var userModel = new UserModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Identity;
|
|||||||
|
|
||||||
namespace Hutopy.Web.Features.Users;
|
namespace Hutopy.Web.Features.Users;
|
||||||
|
|
||||||
public class ApplicationUser : IdentityUser<Guid>
|
public class IdentityUser : IdentityUser<Guid>
|
||||||
{
|
{
|
||||||
[MaxLength(255)] public string? Alias { get; set; }
|
[MaxLength(255)] public string? Alias { get; set; }
|
||||||
[MaxLength(255)] public string? Firstname { get; set; }
|
[MaxLength(255)] public string? Firstname { get; set; }
|
||||||
@@ -3,17 +3,17 @@ using Microsoft.Extensions.Options;
|
|||||||
|
|
||||||
namespace Hutopy.Web.Features.Users;
|
namespace Hutopy.Web.Features.Users;
|
||||||
|
|
||||||
public sealed class ApplicationUserManager(
|
public sealed class IdentityUserManager(
|
||||||
IUserStore<ApplicationUser> store,
|
IUserStore<IdentityUser> store,
|
||||||
IOptions<IdentityOptions> optionsAccessor,
|
IOptions<IdentityOptions> optionsAccessor,
|
||||||
IPasswordHasher<ApplicationUser> passwordHasher,
|
IPasswordHasher<IdentityUser> passwordHasher,
|
||||||
IEnumerable<IUserValidator<ApplicationUser>> userValidators,
|
IEnumerable<IUserValidator<IdentityUser>> userValidators,
|
||||||
IEnumerable<IPasswordValidator<ApplicationUser>> passwordValidators,
|
IEnumerable<IPasswordValidator<IdentityUser>> passwordValidators,
|
||||||
ILookupNormalizer keyNormalizer,
|
ILookupNormalizer keyNormalizer,
|
||||||
IdentityErrorDescriber errors,
|
IdentityErrorDescriber errors,
|
||||||
IServiceProvider services,
|
IServiceProvider services,
|
||||||
ILogger<UserManager<ApplicationUser>> logger)
|
ILogger<UserManager<IdentityUser>> logger)
|
||||||
: UserManager<ApplicationUser>(
|
: UserManager<IdentityUser>(
|
||||||
store,
|
store,
|
||||||
optionsAccessor,
|
optionsAccessor,
|
||||||
passwordHasher,
|
passwordHasher,
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
@using Hutopy.Web.Features.Users
|
@using Hutopy.Web.Features.Users
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
@inject SignInManager<ApplicationUser> SignInManager
|
@using IdentityUser = Hutopy.Web.Features.Users.IdentityUser
|
||||||
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
|
|
||||||
@{
|
@{
|
||||||
string? returnUrl = null;
|
string? returnUrl = null;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ builder.Services.AddFastEndpoints();
|
|||||||
builder.Services.AddUsersModule(options =>
|
builder.Services.AddUsersModule(options =>
|
||||||
options.UseNpgsql(
|
options.UseNpgsql(
|
||||||
postgresConnectionString,
|
postgresConnectionString,
|
||||||
o => o.MigrationsHistoryTable("__EFMigrationsHistory", ApplicationDbContext.SchemaName)));
|
o => o.MigrationsHistoryTable("__EFMigrationsHistory", IdentityDbContext.SchemaName)));
|
||||||
builder.Services.AddContentModule(options =>
|
builder.Services.AddContentModule(options =>
|
||||||
options.UseNpgsql(
|
options.UseNpgsql(
|
||||||
postgresConnectionString,
|
postgresConnectionString,
|
||||||
@@ -114,7 +114,7 @@ app.UseAuthentication();
|
|||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
// Initialize and seed the db.
|
// Initialize and seed the db.
|
||||||
await app.InitialiseApplicationDatabaseAsync();
|
await app.InitialiseIdentityDatabaseAsync();
|
||||||
await app.InitialiseContentDbContextAsync();
|
await app.InitialiseContentDbContextAsync();
|
||||||
await app.InitialiseMessagingDbContextAsync();
|
await app.InitialiseMessagingDbContextAsync();
|
||||||
await app.InitialiseMembershipDbContextAsync();
|
await app.InitialiseMembershipDbContextAsync();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public static class WebApplicationExtensions
|
|||||||
using var scope = app.Services.CreateScope();
|
using var scope = app.Services.CreateScope();
|
||||||
|
|
||||||
var seeder = new TestDataSeeder(
|
var seeder = new TestDataSeeder(
|
||||||
scope.ServiceProvider.GetRequiredService<ApplicationUserManager>(),
|
scope.ServiceProvider.GetRequiredService<IdentityUserManager>(),
|
||||||
scope.ServiceProvider.GetRequiredService<ContentDbContext>(),
|
scope.ServiceProvider.GetRequiredService<ContentDbContext>(),
|
||||||
scope.ServiceProvider.GetRequiredService<MessagingDbContext>(),
|
scope.ServiceProvider.GetRequiredService<MessagingDbContext>(),
|
||||||
scope.ServiceProvider.GetRequiredService<MembershipDbContext>());
|
scope.ServiceProvider.GetRequiredService<MembershipDbContext>());
|
||||||
@@ -27,7 +27,7 @@ public static class WebApplicationExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class TestDataSeeder(
|
internal class TestDataSeeder(
|
||||||
ApplicationUserManager userManager,
|
IdentityUserManager userManager,
|
||||||
ContentDbContext contentContext,
|
ContentDbContext contentContext,
|
||||||
MessagingDbContext messagingContext,
|
MessagingDbContext messagingContext,
|
||||||
MembershipDbContext membershipContext)
|
MembershipDbContext membershipContext)
|
||||||
@@ -181,12 +181,12 @@ internal class TestDataSeeder(
|
|||||||
return replies;
|
return replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ApplicationUser> CreateUserAsync(
|
private async Task<IdentityUser> CreateUserAsync(
|
||||||
string name,
|
string name,
|
||||||
string? portraitUrl,
|
string? portraitUrl,
|
||||||
params string[] roles)
|
params string[] roles)
|
||||||
{
|
{
|
||||||
var user = new ApplicationUser
|
var user = new IdentityUser
|
||||||
{
|
{
|
||||||
UserName = $"{name}@test",
|
UserName = $"{name}@test",
|
||||||
Email = $"{name}@test",
|
Email = $"{name}@test",
|
||||||
@@ -204,7 +204,7 @@ internal class TestDataSeeder(
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<ApplicationUser> _users =
|
private readonly List<IdentityUser> _users =
|
||||||
[
|
[
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user