From eae4e3634938470927617284934dc1e353f3440c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com>
Date: Fri, 14 Nov 2025 18:50:49 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=20=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=20token=E5=A4=B1=E6=95=88=E6=A3=80=E6=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/AdminController.cs | 6 ++++--
Learn.Archives.API/Expand/HttpFilter.cs | 16 ++++++++++++----
Learn.Archives.Core/Common/LiveUserInfo.cs | 8 ++++++++
Learn.Archives.Core/Common/OhException.cs | 10 ++++++++++
4 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/Learn.Archives.API/Controllers/AdminController.cs b/Learn.Archives.API/Controllers/AdminController.cs
index ae41ea9..f2a3db7 100644
--- a/Learn.Archives.API/Controllers/AdminController.cs
+++ b/Learn.Archives.API/Controllers/AdminController.cs
@@ -77,7 +77,9 @@ namespace Learn.Archives.API.Controllers
[
new Claim(ClaimEnum.UserCenterRole,"1"),//让所有用户都有用户中心操作权限
new Claim(ClaimEnum.Role,admin.RoleId.ToString()),
- new Claim(ClaimEnum.UserId,admin.RoleId.ToString()),
+ new Claim(ClaimEnum.UserId,admin.Id.ToString()),
+ new Claim(ClaimEnum.UserId,admin.Id.ToString()),
+ new Claim(ClaimEnum.Scope,"档案系统"),
new Claim(ClaimEnum.Id, admin.Id.ToString()),
new Claim(ClaimEnum.Name, admin.Name),
])
@@ -122,7 +124,7 @@ namespace Learn.Archives.API.Controllers
}
///
- /// 导入考试信息
+ /// 导入用户信息
///
///
[HttpPost, ResultIgnore]
diff --git a/Learn.Archives.API/Expand/HttpFilter.cs b/Learn.Archives.API/Expand/HttpFilter.cs
index b0f2395..585faa4 100644
--- a/Learn.Archives.API/Expand/HttpFilter.cs
+++ b/Learn.Archives.API/Expand/HttpFilter.cs
@@ -21,7 +21,7 @@ using Learn.Archives.Core.Common;
using Learn.Archives.Core.Model.Dto;
using Learn.Archives.Core.Model;
using SqlSugar.IOC;
-using static System.Net.Mime.MediaTypeNames;
+using Microsoft.AspNetCore.Authorization;
namespace Learn.Archives.API.Expand
{
@@ -204,7 +204,7 @@ namespace Learn.Archives.API.Expand
Url = context.Request.Path + context.Request.QueryString,
Method = context.Request.Method,
Request = request,
- IP = context.Connection?.RemoteIpAddress?.ToString(),
+ IP = $"{userInfo.Scope} {context.Connection?.RemoteIpAddress?.ToString()}",
ResponseCode = result?.Code ?? -1,
Response = (result != null ? JsonSerializer.Serialize(result) : null) ,
Authorization = context.Request.Headers.ContainsKey("Authorization")
@@ -220,6 +220,15 @@ namespace Learn.Archives.API.Expand
public override async void OnActionExecuting(ActionExecutingContext context)
{
+ // 直接返回原始结果,不封装
+ if (context.HttpContext.GetEndpoint()?
+ .Metadata.GetMetadata() is null
+ && string.IsNullOrEmpty(userInfo.Scope))
+ {
+ //过期的
+ context.Result = new UnauthorizedResult();
+ return;
+ }
Executing400(context);
@@ -241,8 +250,7 @@ namespace Learn.Archives.API.Expand
catch (Exception ex)
{
}
- //添加http请求日志
-
+
base.OnActionExecuted(context);
}
///
diff --git a/Learn.Archives.Core/Common/LiveUserInfo.cs b/Learn.Archives.Core/Common/LiveUserInfo.cs
index e8428e2..81143d0 100644
--- a/Learn.Archives.Core/Common/LiveUserInfo.cs
+++ b/Learn.Archives.Core/Common/LiveUserInfo.cs
@@ -58,5 +58,13 @@ namespace Learn.Archives.Core.Common
{
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Name)?.Value??string.Empty;
}
+
+ ///
+ /// Scope
+ ///
+ public string Scope
+ {
+ get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Scope)?.Value ?? string.Empty;
+ }
}
}
diff --git a/Learn.Archives.Core/Common/OhException.cs b/Learn.Archives.Core/Common/OhException.cs
index fb36166..7012a4c 100644
--- a/Learn.Archives.Core/Common/OhException.cs
+++ b/Learn.Archives.Core/Common/OhException.cs
@@ -38,6 +38,16 @@ namespace Learn.Archives.Core.Common
///
///
public static void ModelError(string message, int code = 400)
+ {
+ throw new OhException(message, code);
+ }
+ ///
+ /// 抛出 模型校验异常
+ ///
+ ///
+ ///
+ ///
+ public static void ToeknError(string message, int code = 401)
{
throw new OhException(message, code);
}
--
2.40.1
From ad4f3c6f9ed7b0ee5d608fcfbbfe405fd898e51e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com>
Date: Mon, 17 Nov 2025 18:22:40 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=BC=96=E8=BE=91?=
=?UTF-8?q?=E5=AD=A6=E7=94=9F=E4=BF=A1=E6=81=AF=E6=97=B6=E5=80=99=E5=87=8F?=
=?UTF-8?q?=E5=85=8D=E9=87=91=E9=A2=9D=E6=9C=AA=E5=A1=AB=E5=86=99=E5=8F=AF?=
=?UTF-8?q?=E8=83=BD=E5=AF=BC=E8=87=B4=E7=9A=84400?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Learn.Archives.Core/Model/Student.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Learn.Archives.Core/Model/Student.cs b/Learn.Archives.Core/Model/Student.cs
index a38227a..7fbd550 100644
--- a/Learn.Archives.Core/Model/Student.cs
+++ b/Learn.Archives.Core/Model/Student.cs
@@ -25,7 +25,7 @@ namespace Learn.Archives.Core.Model
///
/// 减免金额
///
- [SugarColumn(DecimalDigits =2)]
+ [SugarColumn(DecimalDigits =2, IsNullable = true)]
public decimal AmountRelief { get; set; }
///
/// 减免是否申请
--
2.40.1