first commit

This commit is contained in:
2025-02-26 23:42:19 +01:00
commit 777ea98be1
283 changed files with 88266 additions and 0 deletions
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
namespace OpenWarehouse.auth.api.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>, IDataProtectionKeyContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public virtual DbSet<ApplicationUser> ApplicationUsers { get; set; }
public virtual DbSet<ApplicationRole> ApplicationRoles { get; set; }
public DbSet<ApplicationUserTokenRepository> ApplicationUserTokenRepositories { get; set; }
public DbSet<RegisterToken> RegisterTokens { get; set; }
public DbSet<RolePrivilage> RolePrivilages { get; set; }
public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }
}
}
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Design;
namespace OpenWarehouse.auth.api.Data;
public class ApplicationDbFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
// Use the connection string from configuration
var connectionString = configuration.GetConnectionString("DefaultConnection");
optionsBuilder.UseNpgsql(connectionString);
return new ApplicationDbContext(optionsBuilder.Options);
}
}
@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace OpenWarehouse.auth.api.Data;
public class ApplicationRole : IdentityRole
{
public ApplicationRole(bool isGlobalAdmin = false) : base()
{
IsGlobalAdmin = isGlobalAdmin;
}
public ApplicationRole(string roleName, bool isGlobalAdmin = false) : base(roleName)
{
IsGlobalAdmin = isGlobalAdmin;
}
public List<RolePrivilage?> Privilege { get; set; } = new();
public List<RegisterToken>? TokenToCreateUserWithThisRole { get; set; } = new();
[Required]
public bool IsGlobalAdmin { get; set; }
}
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace OpenWarehouse.auth.api.Data;
public class ApplicationUser : IdentityUser
{
public ApplicationUser() : base()
{
}
public ApplicationUser(string username) : base(username)
{
}
[MinLength(2), MaxLength(3)]
public string? DialCode { get; set; }
public List<ApplicationUserTokenRepository> UserToken { get; set; }
}
@@ -0,0 +1,31 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace OpenWarehouse.auth.api.Data;
public class ApplicationUserTokenRepository
{
public ApplicationUserTokenRepository()
{
IsLocked = false;
}
public ApplicationUserTokenRepository(string? guid,ApplicationUser? user ,DateTime? createdTime, DateTime? expireTime) : this()
{
this.Creator = user;
this.GuidToken = guid;
this.CreatedTime = createdTime;
ExpireTime = expireTime;
}
[Key]
public long Id { get; set; }
[Required]
public ApplicationUser? Creator { get; set; }
[Required, MaxLength(37)]
public string? GuidToken { get; set; }
[Required]
public DateTime? CreatedTime { get; set; }
public DateTime? ExpireTime { get; set; }
[Required]
[DefaultValue(false)]
public bool IsLocked { get; set; }
}
@@ -0,0 +1,26 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace OpenWarehouse.auth.api.Data;
[Index(nameof(Token), IsUnique = true)]
public class RegisterToken
{
public RegisterToken()
{
IsUsed = false;
}
[Key]
public long Id { get; set; }
[Required]
public string? Token { get; set; }
public ApplicationUser? Creator { get; set; }
public List<ApplicationRole>? AvaliableRole { get; set; }
[DefaultValue(false)]
[Required]
public bool IsUsed { get; set; }
}
@@ -0,0 +1,19 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace OpenWarehouse.auth.api.Data;
[Index(nameof(Privilage), IsUnique = true)]
public class RolePrivilage()
{
public RolePrivilage(string privilage) : this()
{
this.Privilage = privilage;
}
[Key]
public long Id { get; set; }
[Required, MaxLength(40)]
public string? Privilage { get; set; }
public List<ApplicationRole>? Roles { get; set; }
}