From e41db8772801b51d030893fcfeb654caf743a3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Sat, 28 Feb 2026 12:11:09 +0800 Subject: [PATCH] =?UTF-8?q?Token=E5=88=B7=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Auth/AuthManager.cs | 3 +- YD_Event.Application/Auth/AuthService.cs | 28 ++++++- .../User/AuthAccountService.cs | 70 ------------------ .../User/Dtos/AuthAccountPageOutput.cs | 33 --------- .../User/Dtos/AuthAccountPageQueryInput.cs | 9 --- YD_Event.Application/YD_Event.Application.xml | 73 ++----------------- YD_Event.Application/applicationsettings.json | 2 +- YD_Event.Core/Entities/SysOperationLog.cs | 22 +----- YD_Event.Core/Entities/SysSigninLog.cs | 22 +----- YD_Event.Core/Entities/SysUser.cs | 2 +- YD_Event.Core/InitData/sysuser.txt | 4 +- YD_Event.Core/YD_Event.Core.xml | 42 +---------- 12 files changed, 43 insertions(+), 267 deletions(-) delete mode 100644 YD_Event.Application/User/AuthAccountService.cs delete mode 100644 YD_Event.Application/User/Dtos/AuthAccountPageOutput.cs delete mode 100644 YD_Event.Application/User/Dtos/AuthAccountPageQueryInput.cs diff --git a/YD_Event.Application/Auth/AuthManager.cs b/YD_Event.Application/Auth/AuthManager.cs index 4b68705..98da4c4 100644 --- a/YD_Event.Application/Auth/AuthManager.cs +++ b/YD_Event.Application/Auth/AuthManager.cs @@ -20,7 +20,8 @@ public class AuthManager : ITransient /// /// 是否是超级管理员 /// - public bool IsSuperAdmin => UserId == 1; + public bool IsSuperAdmin => UserId == 1000; + /// /// 登录名 /// diff --git a/YD_Event.Application/Auth/AuthService.cs b/YD_Event.Application/Auth/AuthService.cs index c07186d..85a0e0a 100644 --- a/YD_Event.Application/Auth/AuthService.cs +++ b/YD_Event.Application/Auth/AuthService.cs @@ -1,4 +1,4 @@ -using YD_Event.Application.Auth.Dtos; +using YD_Event.Application.Auth.Dtos; namespace YD_Event.Application.Auth; /// @@ -92,4 +92,30 @@ public class AuthService : IDynamicApiController var stream = new MemoryStream(data.Bytes); return new FileStreamResult(stream, "image/gif"); } + + /// + /// 刷新Token + /// + /// + /// + [HttpPost("refresh")] + public string RefreshToken([FromQuery] string accessToken) + { + var context = _httpContextAccessor.HttpContext; + var refreshToken = context.Request.Headers["x-access-token"].ToString(); + + if (string.IsNullOrWhiteSpace(accessToken) || string.IsNullOrWhiteSpace(refreshToken)) + { + throw Oops.Bah("无效的Token"); + } + + // 交换新的 Token + var newToken = JWTEncryption.Exchange(accessToken, refreshToken); + + // 设置响应报文头 + context.Response.Headers["access-token"] = newToken; + context.Response.Headers["x-access-token"] = refreshToken; // 刷新Token通常保持不变,或者也可以轮换 + + return newToken; + } } \ No newline at end of file diff --git a/YD_Event.Application/User/AuthAccountService.cs b/YD_Event.Application/User/AuthAccountService.cs deleted file mode 100644 index 25607bc..0000000 --- a/YD_Event.Application/User/AuthAccountService.cs +++ /dev/null @@ -1,70 +0,0 @@ -using YD_Event.Application.User.Dtos; - -namespace YD_Event.Application.User; - -/// -/// 微信小程序授权用户 -/// -public class AuthAccountService : IDynamicApiController -{ - private readonly ISqlSugarRepository _repository; - - public AuthAccountService(ISqlSugarRepository repository) - { - _repository = repository; - } - - /// - /// 博客授权用户列表 - /// - /// - /// - [DisplayName("博客授权用户列表")] - [HttpGet] - public async Task> List([FromQuery] AuthAccountPageQueryInput dto) - { - return await _repository.AsQueryable() - .WhereIF(!string.IsNullOrWhiteSpace(dto.Name), x => x.Name.Contains(dto.Name)) - .OrderByDescending(x => x.Id) - .Select(x => new AuthAccountPageOutput - { - Id = x.Id, - Name = x.Name, - Gender = x.Gender, - Type = x.Type, - IsBlogger = x.IsBlogger, - Avatar = x.Avatar, - CreatedTime = x.CreatedTime - }).ToPagedListAsync(dto); - } - - /// - /// 设置博主 - /// - /// - /// - [DisplayName("设置博主")] - [HttpPatch("SetBlogger")] - public async Task SetBlogger(KeyDto dto) - { - await _repository.UpdateAsync(x => new AuthAccount() - { - IsBlogger = !x.IsBlogger - }, x => x.Id == dto.Id); - } - - /// - /// 删除博客用户 - /// - /// - /// - [DisplayName("删除博客用户")] - [HttpDelete("delete")] - public async Task Delete(KeyDto dto) - { - await _repository.UpdateAsync(x => new AuthAccount() - { - DeleteMark = true - }, x => x.Id == dto.Id); - } -} \ No newline at end of file diff --git a/YD_Event.Application/User/Dtos/AuthAccountPageOutput.cs b/YD_Event.Application/User/Dtos/AuthAccountPageOutput.cs deleted file mode 100644 index ae0adc7..0000000 --- a/YD_Event.Application/User/Dtos/AuthAccountPageOutput.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace YD_Event.Application.User.Dtos; - -public class AuthAccountPageOutput -{ - /// - /// 主键 - /// - public long Id { get; set; } - /// - /// 昵称 - /// - public string Name { get; set; } - /// - /// 性别 - /// - public Gender Gender { get; set; } - /// - /// 授权类型 - /// - public string Type { get; set; } - /// - /// 是否是博主 - /// - public bool IsBlogger { get; set; } - /// - /// 头像 - /// - public string Avatar { get; set; } - /// - /// 注册时间 - /// - public DateTime CreatedTime { get; set; } -} \ No newline at end of file diff --git a/YD_Event.Application/User/Dtos/AuthAccountPageQueryInput.cs b/YD_Event.Application/User/Dtos/AuthAccountPageQueryInput.cs deleted file mode 100644 index d1f132e..0000000 --- a/YD_Event.Application/User/Dtos/AuthAccountPageQueryInput.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace YD_Event.Application.User.Dtos; - -public class AuthAccountPageQueryInput : Pagination -{ - /// - /// 昵称 - /// - public string Name { get; set; } -} \ No newline at end of file diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index f7aab97..57ec88d 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -125,6 +125,13 @@ 验证码唯一id + + + 刷新Token + + + + 登录名 @@ -2364,32 +2371,6 @@ - - - 微信小程序授权用户 - - - - - 博客授权用户列表 - - - - - - - 设置博主 - - - - - - - 删除博客用户 - - - - 姓名 @@ -2410,46 +2391,6 @@ 状态(默认启用) - - - 主键 - - - - - 昵称 - - - - - 性别 - - - - - 授权类型 - - - - - 是否是博主 - - - - - 头像 - - - - - 注册时间 - - - - - 昵称 - - 原密码 diff --git a/YD_Event.Application/applicationsettings.json b/YD_Event.Application/applicationsettings.json index f990450..8bf8e50 100644 --- a/YD_Event.Application/applicationsettings.json +++ b/YD_Event.Application/applicationsettings.json @@ -41,7 +41,7 @@ "DbType": "SqlServer", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access、OpenGauss、QuestDB、HG、ClickHouse、GBase、Odbc、Custom "ConnectionString": "Data Source=rm-uf64b8oxdt19pfyxfao.sqlserver.rds.aliyuncs.com;Database=EventServerDB_QA;User ID=qa;Password=Admin@123;Connect Timeout=500;Encrypt=True;TrustServerCertificate=True;", "IsAutoCloseConnection": true, - "EnableInitDb": true // 启用数据库以及数据表初始化(首次运行项目时开启可以自动创建数据库和初始化项目运行的基础数据) + "EnableInitDb": false // 启用数据库以及数据表初始化(首次运行项目时开启可以自动创建数据库和初始化项目运行的基础数据) } ] }, diff --git a/YD_Event.Core/Entities/SysOperationLog.cs b/YD_Event.Core/Entities/SysOperationLog.cs index 273a56f..5d2220b 100644 --- a/YD_Event.Core/Entities/SysOperationLog.cs +++ b/YD_Event.Core/Entities/SysOperationLog.cs @@ -5,7 +5,7 @@ namespace YD_Event.Core.Entities; /// /// 操作日志 /// -public class SysOperationLog : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime +public class SysOperationLog : Entity, ICreatedTime { /// /// 操作用户ID @@ -116,28 +116,8 @@ public class SysOperationLog : Entity, ISoftDelete, ICreatedUserId, ICreat [SugarColumn(ColumnDataType = "text")] public string? Exception { get; set; } - /// - /// 标记删除 - /// - public bool DeleteMark { get; set; } - - /// - /// 创建人 - /// - public long CreatedUserId { get; set; } - /// /// 创建时间 /// public DateTime CreatedTime { get; set; } - - /// - /// 更新人 - /// - public long? UpdatedUserId { get; set; } - - /// - /// 更新时间 - /// - public DateTime? UpdatedTime { get; set; } } \ No newline at end of file diff --git a/YD_Event.Core/Entities/SysSigninLog.cs b/YD_Event.Core/Entities/SysSigninLog.cs index 8538c22..751834e 100644 --- a/YD_Event.Core/Entities/SysSigninLog.cs +++ b/YD_Event.Core/Entities/SysSigninLog.cs @@ -2,7 +2,7 @@ /// /// 用户登录日志 /// -public class SysSigninLog : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime +public class SysSigninLog : Entity, ICreatedTime { /// /// 用户ID @@ -39,28 +39,8 @@ public class SysSigninLog : Entity, ISoftDelete, ICreatedUserId, ICreatedT [SugarColumn(Length = 256)] public string? Message { get; set; } - /// - /// 标记删除 - /// - public bool DeleteMark { get; set; } - - /// - /// 创建人 - /// - public long CreatedUserId { get; set; } - /// /// 创建时间 /// public DateTime CreatedTime { get; set; } - - /// - /// 更新人 - /// - public long? UpdatedUserId { get; set; } - - /// - /// 更新时间 - /// - public DateTime? UpdatedTime { get; set; } } \ No newline at end of file diff --git a/YD_Event.Core/Entities/SysUser.cs b/YD_Event.Core/Entities/SysUser.cs index 30e5b2c..49b36e5 100644 --- a/YD_Event.Core/Entities/SysUser.cs +++ b/YD_Event.Core/Entities/SysUser.cs @@ -8,7 +8,7 @@ namespace YD_Event.Core.Entities; public class SysUser : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, IUpdatedUserId, IUpdatedTime, IAvailability { /// - /// 用户名 + /// 账号 /// [SugarColumn(Length = 32)] public string Account { get; set; } diff --git a/YD_Event.Core/InitData/sysuser.txt b/YD_Event.Core/InitData/sysuser.txt index 1c68f46..21b2d0f 100644 --- a/YD_Event.Core/InitData/sysuser.txt +++ b/YD_Event.Core/InitData/sysuser.txt @@ -2,7 +2,7 @@ { "Id": 1000, "Account": "admin", - "Password": "9658b68df5e6208e97ae6c8f4eac6c39", + "Password": "4a90afb9ffacbcdea4758f4c46417d2a", "Name": "管理员", "Gender": 1, "OrgId": 1000, @@ -17,7 +17,7 @@ { "Id": 1001, "Account": "mazipeng", - "Password": "9658b68df5e6208e97ae6c8f4eac6c39", + "Password": "4a90afb9ffacbcdea4758f4c46417d2a", "Name": "马梓彭", "Gender": 1, "OrgId": 1000, diff --git a/YD_Event.Core/YD_Event.Core.xml b/YD_Event.Core/YD_Event.Core.xml index e75dee9..70e68af 100644 --- a/YD_Event.Core/YD_Event.Core.xml +++ b/YD_Event.Core/YD_Event.Core.xml @@ -2730,31 +2730,11 @@ 异常信息 - - - 标记删除 - - - - - 创建人 - - 创建时间 - - - 更新人 - - - - - 更新时间 - - 组织机构信息表 @@ -2950,31 +2930,11 @@ 消息 - - - 标记删除 - - - - - 创建人 - - 创建时间 - - - 更新人 - - - - - 更新时间 - - 系统用户表 @@ -2982,7 +2942,7 @@ - 用户名 + 账号