develop #4
@ -18,15 +18,20 @@
 | 
			
		||||
                <span asp-validation-for="Input.Email" class="text-danger"></span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-floating mb-3">
 | 
			
		||||
                <input asp-for="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
 | 
			
		||||
                <input asp-for="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="请输入密码" />
 | 
			
		||||
                <label asp-for="Input.Password">密码</label>
 | 
			
		||||
                <span asp-validation-for="Input.Password" class="text-danger"></span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-floating mb-3">
 | 
			
		||||
                <input asp-for="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
 | 
			
		||||
                <input asp-for="Input.ConfirmPassword" class="form-control" autocomplete="new-sex" aria-required="true" placeholder="确认密码" />
 | 
			
		||||
                <label asp-for="Input.ConfirmPassword">确认密码</label>
 | 
			
		||||
                <span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-floating mb-3">
 | 
			
		||||
                <input asp-for="Input.Sex" class="form-control" autocomplete="username" aria-required="true" placeholder="男/女" />
 | 
			
		||||
                <label asp-for="Input.Sex">性别</label>
 | 
			
		||||
                <span asp-validation-for="Input.Sex" class="text-danger"></span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">注册</button>
 | 
			
		||||
        </form>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除指定用户。
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userId">要删除的用户的唯一标识符。</param>
 | 
			
		||||
    /// <returns>返回操作结果,包含状态码、消息和数据。如果删除成功,则返回200状态码;如果用户ID为空或未找到指定用户,则分别返回400或404状态码;若删除过程中出现错误,则返回500状态码并附带错误信息。</returns>
 | 
			
		||||
    [HttpPost]
 | 
			
		||||
    public async Task<IActionResult> 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<IActionResult> 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));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 通过角色查询用户,支持分页
 | 
			
		||||
    /// </summary>
 | 
			
		||||
 | 
			
		||||
@ -93,6 +93,14 @@ namespace AGSS.Migrations
 | 
			
		||||
                    b.Property<DateTimeOffset?>("LockoutEnd")
 | 
			
		||||
                        .HasColumnType("timestamp with time zone");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("MenuCode")
 | 
			
		||||
                        .HasMaxLength(500)
 | 
			
		||||
                        .HasColumnType("character varying(500)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("MenuName")
 | 
			
		||||
                        .HasMaxLength(500)
 | 
			
		||||
                        .HasColumnType("character varying(500)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("NormalizedEmail")
 | 
			
		||||
                        .HasMaxLength(256)
 | 
			
		||||
                        .HasColumnType("character varying(256)");
 | 
			
		||||
 | 
			
		||||
@ -1,67 +0,0 @@
 | 
			
		||||
// <auto-generated />
 | 
			
		||||
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<Guid>("Id")
 | 
			
		||||
                        .ValueGeneratedOnAdd()
 | 
			
		||||
                        .HasColumnType("uuid");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("AuthId")
 | 
			
		||||
                        .IsRequired()
 | 
			
		||||
                        .HasMaxLength(50)
 | 
			
		||||
                        .HasColumnType("character varying(50)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Birthday")
 | 
			
		||||
                        .HasMaxLength(20)
 | 
			
		||||
                        .HasColumnType("character varying(20)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Config")
 | 
			
		||||
                        .HasMaxLength(200)
 | 
			
		||||
                        .HasColumnType("character varying(200)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Description")
 | 
			
		||||
                        .HasMaxLength(100)
 | 
			
		||||
                        .HasColumnType("character varying(100)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("JobCode")
 | 
			
		||||
                        .HasMaxLength(10)
 | 
			
		||||
                        .HasColumnType("character varying(10)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("JobName")
 | 
			
		||||
                        .HasMaxLength(10)
 | 
			
		||||
                        .HasColumnType("character varying(10)");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Sex")
 | 
			
		||||
                        .HasMaxLength(20)
 | 
			
		||||
                        .HasColumnType("character varying(20)");
 | 
			
		||||
 | 
			
		||||
                    b.HasKey("Id");
 | 
			
		||||
 | 
			
		||||
                    b.ToTable("UserModels");
 | 
			
		||||
                });
 | 
			
		||||
#pragma warning restore 612, 618
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								AGSS/Models/DTOs/MenuRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								AGSS/Models/DTOs/MenuRequest.cs
									
									
									
									
									
										Normal file
									
								
							@ -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; }
 | 
			
		||||
}
 | 
			
		||||
@ -17,6 +17,10 @@ public class UserModel:IdentityUser<string>
 | 
			
		||||
    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; }
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ builder.Services.AddDbContext<ApplicationDbContext>(opt =>
 | 
			
		||||
    opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
 | 
			
		||||
 | 
			
		||||
// Identity 配置
 | 
			
		||||
builder.Services.AddIdentity<UserModel, IdentityRole>()
 | 
			
		||||
builder.Services.AddIdentity<UserModel, RoleModel>()
 | 
			
		||||
    .AddEntityFrameworkStores<ApplicationDbContext>()
 | 
			
		||||
    .AddDefaultTokenProviders()
 | 
			
		||||
    .AddDefaultUI();
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ public class Jwt
 | 
			
		||||
        return new JwtSecurityTokenHandler().WriteToken(tokenDescriptor);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public async Task<string> GenerateJwtToken(UserModel user,IList<string> roles)
 | 
			
		||||
    public string GenerateJwtToken(UserModel user,IList<string> roles)
 | 
			
		||||
    {
 | 
			
		||||
        var claims = new List<Claim>();
 | 
			
		||||
        claims.Add(new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()));
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@
 | 
			
		||||
  },
 | 
			
		||||
  "AllowedHosts": "*",
 | 
			
		||||
  "Jwt": {
 | 
			
		||||
    "ExpireMinutes": "4",
 | 
			
		||||
    "Issuer": "https://api.zeronode.cn/api",
 | 
			
		||||
    "Audience": "https://api.zeronode.cn/api",
 | 
			
		||||
    "Key": "7wU9bdVfBsX3jITh0w4bgE6fkvLk8pIcZRSUw6r8HQUnXfslYxlx4c4E0ZAIw4Ak"
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@
 | 
			
		||||
  },
 | 
			
		||||
  "AllowedHosts": "*",
 | 
			
		||||
  "Jwt": {
 | 
			
		||||
    "ExpireMinutes": "4",
 | 
			
		||||
    "Issuer": "https://api.zeronode.cn/api",
 | 
			
		||||
    "Audience": "https://api.zeronode.cn/api",
 | 
			
		||||
    "Key": "7wU9bdVfBsX3jITh0w4bgE6fkvLk8pIcZRSUw6r8HQUnXfslYxlx4c4E0ZAIw4Ak"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user