From 276adfe1544644e040170e5daae28338ee78995c Mon Sep 17 00:00:00 2001 From: luolan Date: Wed, 9 Jul 2025 13:57:43 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0JWT=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/Pages/Account/Login.cshtml.cs | 3 +- .../Identity/Pages/Account/Register.cshtml.cs | 4 +- .../Controllers/Admin/AdminRoleControllers.cs | 117 +++++++ AGSS/DbSet/UserSet.cs | 17 +- .../20250709054553_userrole.Designer.cs | 300 ++++++++++++++++++ AGSS/Migrations/20250709054553_userrole.cs | 22 ++ .../ApplicationDbContextModelSnapshot.cs | 56 ++-- AGSS/Models/Entities/User.cs | 7 +- AGSS/Utilities/Jwt.cs | 44 +-- AGSS/appsettings.json | 6 +- 10 files changed, 519 insertions(+), 57 deletions(-) create mode 100644 AGSS/Controllers/Admin/AdminRoleControllers.cs create mode 100644 AGSS/Migrations/20250709054553_userrole.Designer.cs create mode 100644 AGSS/Migrations/20250709054553_userrole.cs diff --git a/AGSS/Areas/Identity/Pages/Account/Login.cshtml.cs b/AGSS/Areas/Identity/Pages/Account/Login.cshtml.cs index 9411276..25f1832 100644 --- a/AGSS/Areas/Identity/Pages/Account/Login.cshtml.cs +++ b/AGSS/Areas/Identity/Pages/Account/Login.cshtml.cs @@ -127,7 +127,8 @@ namespace AGSS.Areas.Identity.Pages.Account _logger.LogInformation("User logged in."); var user = await _userManager.FindByEmailAsync(Input.Email); - var token = _jwt.GenerateJwtToken(user); + var roles = await _userManager.GetRolesAsync(user); + var token = _jwt.GenerateJwtToken(user,roles); var frontendCallback = $"{Request.Query["frontendCallback"]}?token={token}"; diff --git a/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs b/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs index 4a1d358..8a449c6 100644 --- a/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -128,8 +128,8 @@ namespace AGSS.Areas.Identity.Pages.Account if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); - var user1 = await _userManager.FindByEmailAsync(Input.Email); - var token = _jwt.GenerateJwtToken(user1); + var roles = await _userManager.GetRolesAsync(user); + var token = _jwt.GenerateJwtToken(user,roles); var frontendCallback = $"{Request.Query["frontendCallback"]}?token={token}"; diff --git a/AGSS/Controllers/Admin/AdminRoleControllers.cs b/AGSS/Controllers/Admin/AdminRoleControllers.cs new file mode 100644 index 0000000..60ec061 --- /dev/null +++ b/AGSS/Controllers/Admin/AdminRoleControllers.cs @@ -0,0 +1,117 @@ +using AGSS.Models.Entities; +using AGSS.Models.Template; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; + +namespace AGSS.Controllers.Admin; + +[Authorize(Roles = "Admin")] +[Route("api/v1/Admin/[controller]")] +public class AdminRoleControllers:ControllerBase +{ + + private readonly RoleManager _roleManager; + private readonly UserManager _userManager; // Assuming UserModel is the type of user + + public AdminRoleControllers(RoleManager roleManager, UserManager userManager) + { + _roleManager = roleManager; + _userManager = userManager; + } + + [HttpPost] + public async Task AddRole([FromBody] RoleModel role) + { + if (role == null || string.IsNullOrWhiteSpace(role.Name)) + { + + return Ok(new ReturnTemplate(400,"创建失败,请提供名字","")); + } + + var result = await _roleManager.CreateAsync(role); + if (result.Succeeded) + { + return Ok(new ReturnTemplate(200,"创建成功",role)); + + } + else + { + return Ok(new ReturnTemplate(StatusCodes.Status500InternalServerError,"创建失败","Failed to create role: " + string.Join(", ", result.Errors.Select(e => e.Description)))); + } + } + [HttpPost] + public async Task EndowRole(string userId, string roleName) + { + var user = await _userManager.FindByIdAsync(userId); + if (user == null) + { + return Ok(new ReturnTemplate(400, "用户不存在", "")); + } + + var role = await _roleManager.FindByNameAsync(roleName); + if (role == null) + { + return Ok(new ReturnTemplate(400, "角色不存在", "")); + } + + var result = await _userManager.AddToRoleAsync(user, role.Name); + if (result.Succeeded) + { + return Ok(new ReturnTemplate(200, "角色分配成功", user)); + } + else + { + return Ok(new ReturnTemplate(StatusCodes.Status500InternalServerError, "角色分配失败", "Failed to endow role: " + string.Join(", ", result.Errors.Select(e => e.Description)))); + } + } + + +/// +/// 通过角色查询用户,支持分页 +/// +/// + [HttpPost] + public async Task SearchUserFromRole([FromBody] SearchUserFromRoleRequest request) + { + if (string.IsNullOrWhiteSpace(request.RoleName)) + { + return Ok(new ReturnTemplate(400, "角色名称不能为空", null)); + } + + var role = await _roleManager.FindByNameAsync(request.RoleName); + if (role == null) + { + return Ok(new ReturnTemplate(400, "角色不存在", null)); + } + + var usersInRole = await _userManager.GetUsersInRoleAsync(role.Name); + var totalUsers = usersInRole.Count; + + var pagedUsers = usersInRole + .Skip((request.Page - 1) * request.PageSize) + .Take(request.PageSize) + .ToList(); + + var response = new SearchUserFromRoleResponse + { + TotalCount = totalUsers, + Users = pagedUsers + }; + + return Ok(new ReturnTemplate(200, "查询成功", response)); + } + + public class SearchUserFromRoleRequest + { + public string RoleName { get; set; } + public int Page { get; set; } = 1; + public int PageSize { get; set; } = 10; + } + + public class SearchUserFromRoleResponse + { + public int TotalCount { get; set; } + public List Users { get; set; } + } +} \ No newline at end of file diff --git a/AGSS/DbSet/UserSet.cs b/AGSS/DbSet/UserSet.cs index cc5c531..6d1fb54 100644 --- a/AGSS/DbSet/UserSet.cs +++ b/AGSS/DbSet/UserSet.cs @@ -4,11 +4,26 @@ using Microsoft.EntityFrameworkCore; namespace AGSS.DbSet { - public class ApplicationDbContext : IdentityDbContext + public class ApplicationDbContext : IdentityDbContext { + + public override DbSet Users { get; set; } + public override DbSet Roles { get; set; } + public ApplicationDbContext(DbContextOptions options) : base(options) { } + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + // 在这里添加额外的配置,如果需要的话 + // 例如: + // modelBuilder.Entity().ToTable("CustomUsers"); + // modelBuilder.Entity().ToTable("CustomRoles"); + } } } \ No newline at end of file diff --git a/AGSS/Migrations/20250709054553_userrole.Designer.cs b/AGSS/Migrations/20250709054553_userrole.Designer.cs new file mode 100644 index 0000000..47bab85 --- /dev/null +++ b/AGSS/Migrations/20250709054553_userrole.Designer.cs @@ -0,0 +1,300 @@ +// +using System; +using AGSS.DbSet; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace AGSS.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20250709054553_userrole")] + partial class userrole + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AGSS.Models.Entities.RoleModel", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("Birthday") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Config") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Description") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("JobCode") + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("JobName") + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("Sex") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("AGSS.Models.Entities.RoleModel", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("AGSS.Models.Entities.UserModel", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("AGSS.Models.Entities.UserModel", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("AGSS.Models.Entities.RoleModel", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AGSS.Models.Entities.UserModel", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("AGSS.Models.Entities.UserModel", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AGSS/Migrations/20250709054553_userrole.cs b/AGSS/Migrations/20250709054553_userrole.cs new file mode 100644 index 0000000..47a1543 --- /dev/null +++ b/AGSS/Migrations/20250709054553_userrole.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AGSS.Migrations +{ + /// + public partial class userrole : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs index 5ce1461..74624bb 100644 --- a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,6 +22,32 @@ namespace AGSS.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("AGSS.Models.Entities.RoleModel", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => { b.Property("Id") @@ -109,32 +135,6 @@ namespace AGSS.Migrations b.ToTable("AspNetUsers", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") @@ -243,7 +243,7 @@ namespace AGSS.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("AGSS.Models.Entities.RoleModel", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) @@ -270,7 +270,7 @@ namespace AGSS.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("AGSS.Models.Entities.RoleModel", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) diff --git a/AGSS/Models/Entities/User.cs b/AGSS/Models/Entities/User.cs index 949134f..7949e56 100644 --- a/AGSS/Models/Entities/User.cs +++ b/AGSS/Models/Entities/User.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Identity; namespace AGSS.Models.Entities; -public class UserModel:IdentityUser +public class UserModel:IdentityUser { public string? Sex { get; set; } @@ -18,4 +18,9 @@ public class UserModel:IdentityUser [MaxLength(20)] public string? Birthday { get; set; } +} + +public class RoleModel : IdentityRole +{ + } \ No newline at end of file diff --git a/AGSS/Utilities/Jwt.cs b/AGSS/Utilities/Jwt.cs index 894b36e..b97fbdc 100644 --- a/AGSS/Utilities/Jwt.cs +++ b/AGSS/Utilities/Jwt.cs @@ -15,28 +15,30 @@ public class Jwt _configuration = configuration; } - - - public string GenerateJwtToken(UserModel user) + public string BuildToken(IEnumerable claims) { - var claims = new[] + DateTime expires = DateTime.Now.AddDays(int.Parse(_configuration["Jwt:ExpireMinutes"])); + byte[] keyBytes = Encoding.UTF8.GetBytes(_configuration["Jwt:Key"]); + var secKey = new SymmetricSecurityKey(keyBytes); + + var credentials = new SigningCredentials(secKey, + SecurityAlgorithms.HmacSha256Signature); + var tokenDescriptor = new JwtSecurityToken(expires: expires, + signingCredentials: credentials, claims: claims); + return new JwtSecurityTokenHandler().WriteToken(tokenDescriptor); + } + + public async Task GenerateJwtToken(UserModel user,IList roles) + { + var claims = new List(); + claims.Add(new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString())); + claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); + // var roles = await user.GetRolesAsync(user); + foreach (string role in roles) { - new Claim(JwtRegisteredClaimNames.Sub, user.Email), - new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), - new Claim(ClaimTypes.NameIdentifier, user.Id) - }; - var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes( - _configuration["Jwt:Key"])); - var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); - var expires = DateTime.Now.AddMinutes( - Convert.ToDouble(_configuration["Jwt:ExpireMinutes"])); - var token = new JwtSecurityToken( - issuer: _configuration["Jwt:Issuer"], - audience: _configuration["Jwt:Audience"], - claims: claims, - expires: expires, - signingCredentials: creds - ); - return new JwtSecurityTokenHandler().WriteToken(token); + claims.Add(new Claim(ClaimTypes.Role, role)); + } + string jwtToken = BuildToken(claims); + return jwtToken; } } \ No newline at end of file diff --git a/AGSS/appsettings.json b/AGSS/appsettings.json index ea024a7..f595462 100644 --- a/AGSS/appsettings.json +++ b/AGSS/appsettings.json @@ -9,10 +9,10 @@ "Microsoft": { "ClientId": "1f0c6ff3-a458-466b-ac92-decaa1d8b132", "ClientSecret": "TdY8Q~Tsm1nPl6RZMbDGmVsXblJo1xdDKCoH9ayk" - + } - -}, + + }, "AllowedHosts": "*", "Jwt": { "Issuer": "https://api.zeronode.cn/api", From 64b7c4bd573d53a0d6eb3c72c6918f670b23d9b8 Mon Sep 17 00:00:00 2001 From: luolan Date: Wed, 9 Jul 2025 15:40:47 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=92=8C=E7=AE=A1=E7=90=86=E5=91=98=E8=A7=92=E8=89=B2=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=99=A8=E8=B7=AF=E7=94=B1=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99SQL=E8=84=9A=E6=9C=AC=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Areas/Identity/Pages/Account/Login.cshtml | 127 +++++++++--------- .../Controllers/Admin/AdminRoleControllers.cs | 2 +- AGSS/Controllers/User/UserControllers.cs | 2 +- Areas/Identity/Pages/Account/Register.cshtml | 1 + script.sql | 101 +------------- 5 files changed, 68 insertions(+), 165 deletions(-) create mode 100644 Areas/Identity/Pages/Account/Register.cshtml diff --git a/AGSS/Areas/Identity/Pages/Account/Login.cshtml b/AGSS/Areas/Identity/Pages/Account/Login.cshtml index 0328355..f707aa1 100644 --- a/AGSS/Areas/Identity/Pages/Account/Login.cshtml +++ b/AGSS/Areas/Identity/Pages/Account/Login.cshtml @@ -5,73 +5,72 @@ ViewData["Title"] = "登录"; } -

@ViewData["Title"]

-
-
-
-
-

使用本地账户登录。

-
- -
- - - -
-
- - - -
-
-
diff --git a/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs b/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs index 8a449c6..3884aff 100644 --- a/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/AGSS/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -104,6 +104,12 @@ namespace AGSS.Areas.Identity.Pages.Account [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } + + + [MaxLength(10)] + [Display(Name = "Confirm password")] + public string Sex { get; set; } + } @@ -120,7 +126,8 @@ namespace AGSS.Areas.Identity.Pages.Account if (ModelState.IsValid) { var user = CreateUser(); - + user.Id = Guid.NewGuid().ToString(); + user.Sex = Input.Sex; await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); var result = await _userManager.CreateAsync(user, Input.Password); diff --git a/AGSS/Controllers/Admin/AdminRoleControllers.cs b/AGSS/Controllers/Admin/AdminRoleControllers.cs index ddcb89e..95c7429 100644 --- a/AGSS/Controllers/Admin/AdminRoleControllers.cs +++ b/AGSS/Controllers/Admin/AdminRoleControllers.cs @@ -1,3 +1,4 @@ +using AGSS.Models.DTOs; using AGSS.Models.Entities; using AGSS.Models.Template; using Microsoft.AspNetCore.Authorization; @@ -96,6 +97,69 @@ public class AdminRoleControllers:ControllerBase } + /// + /// 删除指定用户。 + /// + /// 要删除的用户的唯一标识符。 + /// 返回操作结果,包含状态码、消息和数据。如果删除成功,则返回200状态码;如果用户ID为空或未找到指定用户,则分别返回400或404状态码;若删除过程中出现错误,则返回500状态码并附带错误信息。 + [HttpPost] + public async Task DelUser(string userId) + { + if (string.IsNullOrWhiteSpace(userId)) + { + return Ok(new ReturnTemplate(400, "你填写的用户ID是空的~", null)); + } + + var user = await _userManager.FindByIdAsync(userId); + if (user == null) + { + return Ok(new ReturnTemplate(404, "未找到指定用户哦·~", null)); + } + + // 删除用户 + var result = await _userManager.DeleteAsync(user); + if (result.Succeeded) + { + return Ok(new ReturnTemplate(200, "用户删除成功,不要留念这个用户哦~", null)); + } + else + { + return StatusCode(500, new ReturnTemplate(500, "发生了一些不可预料的错误,555", result.Errors)); + } + } + + + [HttpPost] + public async Task SetMenu([FromBody]MenuRequest request) + { + if (string.IsNullOrWhiteSpace(request.Id) || string.IsNullOrWhiteSpace(request.MenuName)) + { + return Ok(new ReturnTemplate(400, "请求参数无效(有的参数是空的哦~)", "")); + } + var user=await _userManager.FindByIdAsync(request.Id); + if (user==null) + { + return Ok(new ReturnTemplate(404, "Sorry,你输入的用户我们找不到!", "")); + } + user.MenuCode = request.MenuCode; + user.MenuName = request.MenuName; + var result= await _userManager.UpdateAsync(user); + if (result.Succeeded) + { + return Ok(new ReturnTemplate(200, "配置成功啦!", "")); + } + else + { + return StatusCode(500, new ReturnTemplate(500, "删除用户时发生错误", result.Errors)); + } + + + } + + + + + /// /// 通过角色查询用户,支持分页 /// diff --git a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs index 74624bb..058cb5a 100644 --- a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs @@ -93,6 +93,14 @@ namespace AGSS.Migrations b.Property("LockoutEnd") .HasColumnType("timestamp with time zone"); + b.Property("MenuCode") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("MenuName") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + b.Property("NormalizedEmail") .HasMaxLength(256) .HasColumnType("character varying(256)"); diff --git a/AGSS/Migrations/DBContextModelSnapshot.cs b/AGSS/Migrations/DBContextModelSnapshot.cs deleted file mode 100644 index e76171d..0000000 --- a/AGSS/Migrations/DBContextModelSnapshot.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -using System; -using AGSS.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(DBContext))] - partial class DBContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AuthId") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Birthday") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("Config") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Description") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("JobCode") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("JobName") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("Sex") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.HasKey("Id"); - - b.ToTable("UserModels"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Models/DTOs/MenuRequest.cs b/AGSS/Models/DTOs/MenuRequest.cs new file mode 100644 index 0000000..b8a76c2 --- /dev/null +++ b/AGSS/Models/DTOs/MenuRequest.cs @@ -0,0 +1,8 @@ +namespace AGSS.Models.DTOs; + +public struct MenuRequest +{ + public string Id { get; set; } + public string MenuName { get; set; } + public string? MenuCode { get; set; } +} \ No newline at end of file diff --git a/AGSS/Models/Entities/User.cs b/AGSS/Models/Entities/User.cs index 7949e56..0ac6258 100644 --- a/AGSS/Models/Entities/User.cs +++ b/AGSS/Models/Entities/User.cs @@ -17,6 +17,10 @@ public class UserModel:IdentityUser public string? JobName { get; set; } [MaxLength(20)] public string? Birthday { get; set; } + [MaxLength(500)] + public string? MenuCode { get; set; } + [MaxLength(500)] + public string? MenuName { get; set; } } diff --git a/AGSS/Program.cs b/AGSS/Program.cs index e68de46..427490c 100644 --- a/AGSS/Program.cs +++ b/AGSS/Program.cs @@ -33,7 +33,7 @@ builder.Services.AddDbContext(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext"))); // Identity 配置 -builder.Services.AddIdentity() +builder.Services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders() .AddDefaultUI(); diff --git a/AGSS/Utilities/Jwt.cs b/AGSS/Utilities/Jwt.cs index b97fbdc..6d3c49f 100644 --- a/AGSS/Utilities/Jwt.cs +++ b/AGSS/Utilities/Jwt.cs @@ -28,7 +28,7 @@ public class Jwt return new JwtSecurityTokenHandler().WriteToken(tokenDescriptor); } - public async Task GenerateJwtToken(UserModel user,IList roles) + public string GenerateJwtToken(UserModel user,IList roles) { var claims = new List(); claims.Add(new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString())); diff --git a/AGSS/appsettings.Development.json b/AGSS/appsettings.Development.json index f061d7b..d1c269e 100644 --- a/AGSS/appsettings.Development.json +++ b/AGSS/appsettings.Development.json @@ -15,6 +15,7 @@ }, "AllowedHosts": "*", "Jwt": { + "ExpireMinutes": "4", "Issuer": "https://api.zeronode.cn/api", "Audience": "https://api.zeronode.cn/api", "Key": "7wU9bdVfBsX3jITh0w4bgE6fkvLk8pIcZRSUw6r8HQUnXfslYxlx4c4E0ZAIw4Ak" diff --git a/AGSS/appsettings.json b/AGSS/appsettings.json index f595462..6527a3d 100644 --- a/AGSS/appsettings.json +++ b/AGSS/appsettings.json @@ -15,6 +15,7 @@ }, "AllowedHosts": "*", "Jwt": { + "ExpireMinutes": "4", "Issuer": "https://api.zeronode.cn/api", "Audience": "https://api.zeronode.cn/api", "Key": "7wU9bdVfBsX3jITh0w4bgE6fkvLk8pIcZRSUw6r8HQUnXfslYxlx4c4E0ZAIw4Ak" From 87d75c8743dcd844fec5e61aae81db8ba74c6b45 Mon Sep 17 00:00:00 2001 From: luolan Date: Wed, 9 Jul 2025 23:13:28 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E5=B9=B6=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20250702100149_Initial.Designer.cs | 53 ---- AGSS/Migrations/20250702100149_Initial.cs | 36 --- .../20250702110815_usernew.Designer.cs | 45 --- AGSS/Migrations/20250702110815_usernew.cs | 40 --- .../20250705081221_newuser.Designer.cs | 70 ---- AGSS/Migrations/20250705081221_newuser.cs | 102 ------ .../20250708111442_user.Designer.cs | 300 ------------------ AGSS/Migrations/20250708111442_user.cs | 229 ------------- .../20250709054553_userrole.Designer.cs | 300 ------------------ AGSS/Migrations/20250709054553_userrole.cs | 22 -- script.sql | 151 ++++++++- 11 files changed, 150 insertions(+), 1198 deletions(-) delete mode 100644 AGSS/Migrations/20250702100149_Initial.Designer.cs delete mode 100644 AGSS/Migrations/20250702100149_Initial.cs delete mode 100644 AGSS/Migrations/20250702110815_usernew.Designer.cs delete mode 100644 AGSS/Migrations/20250702110815_usernew.cs delete mode 100644 AGSS/Migrations/20250705081221_newuser.Designer.cs delete mode 100644 AGSS/Migrations/20250705081221_newuser.cs delete mode 100644 AGSS/Migrations/20250708111442_user.Designer.cs delete mode 100644 AGSS/Migrations/20250708111442_user.cs delete mode 100644 AGSS/Migrations/20250709054553_userrole.Designer.cs delete mode 100644 AGSS/Migrations/20250709054553_userrole.cs diff --git a/AGSS/Migrations/20250702100149_Initial.Designer.cs b/AGSS/Migrations/20250702100149_Initial.Designer.cs deleted file mode 100644 index fb2159a..0000000 --- a/AGSS/Migrations/20250702100149_Initial.Designer.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -using System; -using AGSS.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(DBContext))] - [Migration("20250702100149_Initial")] - partial class Initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AuthId") - .IsRequired() - .HasColumnType("text"); - - b.Property("Email") - .IsRequired() - .HasColumnType("text"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("UserModels"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Migrations/20250702100149_Initial.cs b/AGSS/Migrations/20250702100149_Initial.cs deleted file mode 100644 index ba17990..0000000 --- a/AGSS/Migrations/20250702100149_Initial.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace AGSS.Migrations -{ - /// - public partial class Initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "UserModels", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - AuthId = table.Column(type: "text", nullable: false), - Email = table.Column(type: "text", nullable: false), - Password = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserModels", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "UserModels"); - } - } -} diff --git a/AGSS/Migrations/20250702110815_usernew.Designer.cs b/AGSS/Migrations/20250702110815_usernew.Designer.cs deleted file mode 100644 index 4d069d8..0000000 --- a/AGSS/Migrations/20250702110815_usernew.Designer.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -using System; -using AGSS.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(DBContext))] - [Migration("20250702110815_usernew")] - partial class usernew - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AuthId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("UserModels"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Migrations/20250702110815_usernew.cs b/AGSS/Migrations/20250702110815_usernew.cs deleted file mode 100644 index 31a4115..0000000 --- a/AGSS/Migrations/20250702110815_usernew.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace AGSS.Migrations -{ - /// - public partial class usernew : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Email", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "Password", - table: "UserModels"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Email", - table: "UserModels", - type: "text", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "Password", - table: "UserModels", - type: "text", - nullable: false, - defaultValue: ""); - } - } -} diff --git a/AGSS/Migrations/20250705081221_newuser.Designer.cs b/AGSS/Migrations/20250705081221_newuser.Designer.cs deleted file mode 100644 index d2c8e0b..0000000 --- a/AGSS/Migrations/20250705081221_newuser.Designer.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -using System; -using AGSS.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(DBContext))] - [Migration("20250705081221_newuser")] - partial class newuser - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AuthId") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Birthday") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("Config") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Description") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("JobCode") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("JobName") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("Sex") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.HasKey("Id"); - - b.ToTable("UserModels"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Migrations/20250705081221_newuser.cs b/AGSS/Migrations/20250705081221_newuser.cs deleted file mode 100644 index 1dfddc2..0000000 --- a/AGSS/Migrations/20250705081221_newuser.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace AGSS.Migrations -{ - /// - public partial class newuser : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "AuthId", - table: "UserModels", - type: "character varying(50)", - maxLength: 50, - nullable: false, - oldClrType: typeof(string), - oldType: "text"); - - migrationBuilder.AddColumn( - name: "Birthday", - table: "UserModels", - type: "character varying(20)", - maxLength: 20, - nullable: true); - - migrationBuilder.AddColumn( - name: "Config", - table: "UserModels", - type: "character varying(200)", - maxLength: 200, - nullable: true); - - migrationBuilder.AddColumn( - name: "Description", - table: "UserModels", - type: "character varying(100)", - maxLength: 100, - nullable: true); - - migrationBuilder.AddColumn( - name: "JobCode", - table: "UserModels", - type: "character varying(10)", - maxLength: 10, - nullable: true); - - migrationBuilder.AddColumn( - name: "JobName", - table: "UserModels", - type: "character varying(10)", - maxLength: 10, - nullable: true); - - migrationBuilder.AddColumn( - name: "Sex", - table: "UserModels", - type: "character varying(20)", - maxLength: 20, - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Birthday", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "Config", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "Description", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "JobCode", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "JobName", - table: "UserModels"); - - migrationBuilder.DropColumn( - name: "Sex", - table: "UserModels"); - - migrationBuilder.AlterColumn( - name: "AuthId", - table: "UserModels", - type: "text", - nullable: false, - oldClrType: typeof(string), - oldType: "character varying(50)", - oldMaxLength: 50); - } - } -} diff --git a/AGSS/Migrations/20250708111442_user.Designer.cs b/AGSS/Migrations/20250708111442_user.Designer.cs deleted file mode 100644 index f618b64..0000000 --- a/AGSS/Migrations/20250708111442_user.Designer.cs +++ /dev/null @@ -1,300 +0,0 @@ -// -using System; -using AGSS.DbSet; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20250708111442_user")] - partial class user - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("Birthday") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Config") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Description") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("JobCode") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("JobName") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Sex") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - 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("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Migrations/20250708111442_user.cs b/AGSS/Migrations/20250708111442_user.cs deleted file mode 100644 index bcc2e1d..0000000 --- a/AGSS/Migrations/20250708111442_user.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - /// - public partial class user : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - Sex = table.Column(type: "text", nullable: true), - Description = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - Config = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), - JobCode = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), - JobName = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), - Birthday = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), - UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "text", nullable: true), - SecurityStamp = table.Column(type: "text", nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true), - PhoneNumber = table.Column(type: "text", nullable: true), - PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), - TwoFactorEnabled = table.Column(type: "boolean", nullable: false), - LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), - LockoutEnabled = table.Column(type: "boolean", nullable: false), - AccessFailedCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(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(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(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(type: "text", nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(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(type: "text", nullable: false), - RoleId = table.Column(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(type: "text", nullable: false), - LoginProvider = table.Column(type: "text", nullable: false), - Name = table.Column(type: "text", nullable: false), - Value = table.Column(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); - } - - /// - 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"); - } - } -} diff --git a/AGSS/Migrations/20250709054553_userrole.Designer.cs b/AGSS/Migrations/20250709054553_userrole.Designer.cs deleted file mode 100644 index 47bab85..0000000 --- a/AGSS/Migrations/20250709054553_userrole.Designer.cs +++ /dev/null @@ -1,300 +0,0 @@ -// -using System; -using AGSS.DbSet; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace AGSS.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20250709054553_userrole")] - partial class userrole - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("AGSS.Models.Entities.RoleModel", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("AGSS.Models.Entities.UserModel", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("Birthday") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Config") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Description") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("JobCode") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("JobName") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Sex") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("AGSS.Models.Entities.RoleModel", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("AGSS.Models.Entities.RoleModel", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("AGSS.Models.Entities.UserModel", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/AGSS/Migrations/20250709054553_userrole.cs b/AGSS/Migrations/20250709054553_userrole.cs deleted file mode 100644 index 47a1543..0000000 --- a/AGSS/Migrations/20250709054553_userrole.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace AGSS.Migrations -{ - /// - public partial class userrole : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/script.sql b/script.sql index df7c096..577aeff 100644 --- a/script.sql +++ b/script.sql @@ -1,6 +1,155 @@ -START TRANSACTION; +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" character varying(150) NOT NULL, + "ProductVersion" character varying(32) NOT NULL, + CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") +); + +START TRANSACTION; +CREATE TABLE "AspNetRoles" ( + "Id" text NOT NULL, + "Name" character varying(256), + "NormalizedName" character varying(256), + "ConcurrencyStamp" text, + CONSTRAINT "PK_AspNetRoles" PRIMARY KEY ("Id") +); + +CREATE TABLE "AspNetUsers" ( + "Id" text NOT NULL, + "Sex" text, + "Description" character varying(100), + "Config" character varying(200), + "JobCode" character varying(10), + "JobName" character varying(10), + "Birthday" character varying(20), + "UserName" character varying(256), + "NormalizedUserName" character varying(256), + "Email" character varying(256), + "NormalizedEmail" character varying(256), + "EmailConfirmed" boolean NOT NULL, + "PasswordHash" text, + "SecurityStamp" text, + "ConcurrencyStamp" text, + "PhoneNumber" text, + "PhoneNumberConfirmed" boolean NOT NULL, + "TwoFactorEnabled" boolean NOT NULL, + "LockoutEnd" timestamp with time zone, + "LockoutEnabled" boolean NOT NULL, + "AccessFailedCount" integer NOT NULL, + CONSTRAINT "PK_AspNetUsers" PRIMARY KEY ("Id") +); + +CREATE TABLE "AspNetRoleClaims" ( + "Id" integer GENERATED BY DEFAULT AS IDENTITY, + "RoleId" text NOT NULL, + "ClaimType" text, + "ClaimValue" text, + CONSTRAINT "PK_AspNetRoleClaims" PRIMARY KEY ("Id"), + CONSTRAINT "FK_AspNetRoleClaims_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE +); + +CREATE TABLE "AspNetUserClaims" ( + "Id" integer GENERATED BY DEFAULT AS IDENTITY, + "UserId" text NOT NULL, + "ClaimType" text, + "ClaimValue" text, + CONSTRAINT "PK_AspNetUserClaims" PRIMARY KEY ("Id"), + CONSTRAINT "FK_AspNetUserClaims_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE +); + +CREATE TABLE "AspNetUserLogins" ( + "LoginProvider" text NOT NULL, + "ProviderKey" text NOT NULL, + "ProviderDisplayName" text, + "UserId" text NOT NULL, + CONSTRAINT "PK_AspNetUserLogins" PRIMARY KEY ("LoginProvider", "ProviderKey"), + CONSTRAINT "FK_AspNetUserLogins_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE +); + +CREATE TABLE "AspNetUserRoles" ( + "UserId" text NOT NULL, + "RoleId" text NOT NULL, + CONSTRAINT "PK_AspNetUserRoles" PRIMARY KEY ("UserId", "RoleId"), + CONSTRAINT "FK_AspNetUserRoles_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE, + CONSTRAINT "FK_AspNetUserRoles_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE +); + +CREATE TABLE "AspNetUserTokens" ( + "UserId" text NOT NULL, + "LoginProvider" text NOT NULL, + "Name" text NOT NULL, + "Value" text, + CONSTRAINT "PK_AspNetUserTokens" PRIMARY KEY ("UserId", "LoginProvider", "Name"), + CONSTRAINT "FK_AspNetUserTokens_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE +); + +CREATE INDEX "IX_AspNetRoleClaims_RoleId" ON "AspNetRoleClaims" ("RoleId"); + +CREATE UNIQUE INDEX "RoleNameIndex" ON "AspNetRoles" ("NormalizedName"); + +CREATE INDEX "IX_AspNetUserClaims_UserId" ON "AspNetUserClaims" ("UserId"); + +CREATE INDEX "IX_AspNetUserLogins_UserId" ON "AspNetUserLogins" ("UserId"); + +CREATE INDEX "IX_AspNetUserRoles_RoleId" ON "AspNetUserRoles" ("RoleId"); + +CREATE INDEX "EmailIndex" ON "AspNetUsers" ("NormalizedEmail"); + +CREATE UNIQUE INDEX "UserNameIndex" ON "AspNetUsers" ("NormalizedUserName"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20250708111442_user', '9.0.6'); + INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20250709054553_userrole', '9.0.6'); +ALTER TABLE "AspNetUsers" ADD "MenuCode" character varying(1000); + +ALTER TABLE "AspNetUsers" ADD "MenuName" character varying(1000); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20250709141702_Menu', '9.0.6'); + +ALTER TABLE "AspNetUserTokens" ALTER COLUMN "UserId" TYPE uuid; + +ALTER TABLE "AspNetUsers" ALTER COLUMN "MenuName" TYPE character varying(500); + +ALTER TABLE "AspNetUsers" ALTER COLUMN "MenuCode" TYPE character varying(500); + +ALTER TABLE "AspNetUsers" ALTER COLUMN "Id" TYPE uuid; + +ALTER TABLE "AspNetUserRoles" ALTER COLUMN "RoleId" TYPE uuid; + +ALTER TABLE "AspNetUserRoles" ALTER COLUMN "UserId" TYPE uuid; + +ALTER TABLE "AspNetUserLogins" ALTER COLUMN "UserId" TYPE uuid; + +ALTER TABLE "AspNetUserClaims" ALTER COLUMN "UserId" TYPE uuid; + +ALTER TABLE "AspNetRoles" ALTER COLUMN "Id" TYPE uuid; + +ALTER TABLE "AspNetRoleClaims" ALTER COLUMN "RoleId" TYPE uuid; + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20250709142723_guiduser', '9.0.6'); + +ALTER TABLE "AspNetUserTokens" ALTER COLUMN "UserId" TYPE text; + +ALTER TABLE "AspNetUsers" ALTER COLUMN "Id" TYPE text; + +ALTER TABLE "AspNetUserRoles" ALTER COLUMN "RoleId" TYPE text; + +ALTER TABLE "AspNetUserRoles" ALTER COLUMN "UserId" TYPE text; + +ALTER TABLE "AspNetUserLogins" ALTER COLUMN "UserId" TYPE text; + +ALTER TABLE "AspNetUserClaims" ALTER COLUMN "UserId" TYPE text; + +ALTER TABLE "AspNetRoles" ALTER COLUMN "Id" TYPE text; + +ALTER TABLE "AspNetRoleClaims" ALTER COLUMN "RoleId" TYPE text; + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20250709144140_stringuser', '9.0.6'); + COMMIT; From 9f407c422c8b6cec9d0f9c92ff66269acaa1ae8c Mon Sep 17 00:00:00 2001 From: luolan Date: Wed, 9 Jul 2025 23:46:36 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E7=9A=84=E8=8F=9C=E5=8D=95=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=B9=B6=E4=BC=98=E5=8C=96=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E5=92=8C=E8=AE=A4=E8=AF=81=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Account/Manage/EnableAuthenticator.cshtml | 5 +- script.sql | 56 +------------------ 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/AGSS/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml b/AGSS/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml index fefa57f..62a62a3 100644 --- a/AGSS/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml +++ b/AGSS/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml @@ -49,5 +49,8 @@
@section Scripts { - + @await Html.PartialAsync("_ValidationScriptsPartial") + + + } diff --git a/script.sql b/script.sql index 577aeff..73a8d5b 100644 --- a/script.sql +++ b/script.sql @@ -21,6 +21,8 @@ CREATE TABLE "AspNetUsers" ( "JobCode" character varying(10), "JobName" character varying(10), "Birthday" character varying(20), + "MenuCode" character varying(500), + "MenuName" character varying(500), "UserName" character varying(256), "NormalizedUserName" character varying(256), "Email" character varying(256), @@ -97,59 +99,7 @@ CREATE INDEX "EmailIndex" ON "AspNetUsers" ("NormalizedEmail"); CREATE UNIQUE INDEX "UserNameIndex" ON "AspNetUsers" ("NormalizedUserName"); INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250708111442_user', '9.0.6'); - -INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250709054553_userrole', '9.0.6'); - -ALTER TABLE "AspNetUsers" ADD "MenuCode" character varying(1000); - -ALTER TABLE "AspNetUsers" ADD "MenuName" character varying(1000); - -INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250709141702_Menu', '9.0.6'); - -ALTER TABLE "AspNetUserTokens" ALTER COLUMN "UserId" TYPE uuid; - -ALTER TABLE "AspNetUsers" ALTER COLUMN "MenuName" TYPE character varying(500); - -ALTER TABLE "AspNetUsers" ALTER COLUMN "MenuCode" TYPE character varying(500); - -ALTER TABLE "AspNetUsers" ALTER COLUMN "Id" TYPE uuid; - -ALTER TABLE "AspNetUserRoles" ALTER COLUMN "RoleId" TYPE uuid; - -ALTER TABLE "AspNetUserRoles" ALTER COLUMN "UserId" TYPE uuid; - -ALTER TABLE "AspNetUserLogins" ALTER COLUMN "UserId" TYPE uuid; - -ALTER TABLE "AspNetUserClaims" ALTER COLUMN "UserId" TYPE uuid; - -ALTER TABLE "AspNetRoles" ALTER COLUMN "Id" TYPE uuid; - -ALTER TABLE "AspNetRoleClaims" ALTER COLUMN "RoleId" TYPE uuid; - -INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250709142723_guiduser', '9.0.6'); - -ALTER TABLE "AspNetUserTokens" ALTER COLUMN "UserId" TYPE text; - -ALTER TABLE "AspNetUsers" ALTER COLUMN "Id" TYPE text; - -ALTER TABLE "AspNetUserRoles" ALTER COLUMN "RoleId" TYPE text; - -ALTER TABLE "AspNetUserRoles" ALTER COLUMN "UserId" TYPE text; - -ALTER TABLE "AspNetUserLogins" ALTER COLUMN "UserId" TYPE text; - -ALTER TABLE "AspNetUserClaims" ALTER COLUMN "UserId" TYPE text; - -ALTER TABLE "AspNetRoles" ALTER COLUMN "Id" TYPE text; - -ALTER TABLE "AspNetRoleClaims" ALTER COLUMN "RoleId" TYPE text; - -INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250709144140_stringuser', '9.0.6'); +VALUES ('20250709144855_Initial', '9.0.6'); COMMIT;