Backend login and register
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Infrastructure.Configuration;
|
||||
|
||||
public class RoleConfiguration : IEntityTypeConfiguration<Role>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Role> builder)
|
||||
{
|
||||
builder.ToTable("Roles", "auth");
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.HasMany(x => x.UserRoles)
|
||||
.WithOne(x => x.Role)
|
||||
.HasForeignKey(x => x.RoleId);
|
||||
|
||||
builder.HasData(
|
||||
new Role { Id = 1, Name = "SuperAdmin" },
|
||||
new Role { Id = 2, Name = "Admin" },
|
||||
new Role { Id = 3, Name = "User" }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Infrastructure.Configuration;
|
||||
|
||||
public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
builder.ToTable("Users", "auth");
|
||||
|
||||
builder.HasKey(k => k.Id);
|
||||
|
||||
builder.Property(x => x.Username)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)");
|
||||
|
||||
builder.Property(x => x.Password)
|
||||
.IsRequired()
|
||||
.HasMaxLength(250)
|
||||
.HasColumnType("varchar(250)");
|
||||
|
||||
builder.Property(x => x.Email)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("varchar(100)")
|
||||
.HasAnnotation("RegularExpression", @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
|
||||
|
||||
builder.HasMany(x => x.UserRoles)
|
||||
.WithOne(x => x.User)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
builder.HasData(
|
||||
new User
|
||||
{
|
||||
Id = 1, Username = "Superadmin", Email = "superadmin@wenske-services-development.de",
|
||||
Password = "AQAAAAIAAYagAAAAEADJEu1s5qUJyP4gDUrBGyqSNtKU2IKBpZm0JqfyvOkJnqVeOHZBUrEhNr7IdQRDBQ=="
|
||||
},
|
||||
new User
|
||||
{
|
||||
Id = 2, Username = "Admin", Email = "admin@wenske-services-development.de",
|
||||
Password = "AQAAAAIAAYagAAAAEIOUiJUfMrM1Lpt4Ae3FLQOB/Bk6WHtndRAWUp132afVunMvRqkT6Hhh+27kkNW8YQ=="
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Infrastructure.Configuration;
|
||||
|
||||
public class UserRoleConfiguration : IEntityTypeConfiguration<UserRole>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserRole> builder)
|
||||
{
|
||||
builder.ToTable("UserRoles", "auth");
|
||||
builder.HasKey(x => new { x.UserId, x.RoleId });
|
||||
builder.HasOne(x => x.User)
|
||||
.WithMany(x => x.UserRoles)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
builder.HasOne(x => x.Role)
|
||||
.WithMany(x => x.UserRoles)
|
||||
.HasForeignKey(x => x.RoleId);
|
||||
|
||||
builder.HasData(
|
||||
new UserRole { UserId = 1, RoleId = 1 },
|
||||
new UserRole { UserId = 2, RoleId = 2 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user