修正了swgger生成的类型名,SimApiAuth 如果不加参数,则默认接受所有登录了的用户请求.

This commit is contained in:
2025-12-23 08:18:11 +08:00
parent d50d32f032
commit 81e166ad45
2 changed files with 51 additions and 23 deletions
+4 -9
View File
@@ -13,13 +13,13 @@ namespace SimApi.Attributes;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class SimApiAuthAttribute : ActionFilterAttribute
{
private string[] Types { get; }
private string[]? Types { get; }
//默认是user登录类型
public SimApiAuthAttribute()
{
Types = new[] { "user" };
Types = null;
}
//只检测一种用户类型的快捷方式
@@ -34,13 +34,6 @@ public class SimApiAuthAttribute : ActionFilterAttribute
Types = types;
}
//只检测一种用户类型的快捷方式
public SimApiAuthAttribute(string type, string url)
{
Types = new[] { type };
new HttpPostAttribute(url);
}
public override void OnActionExecuting(ActionExecutingContext context)
{
var loginInfo = (SimApiLoginItem)context.HttpContext.Items["LoginInfo"]!;
@@ -49,6 +42,8 @@ public class SimApiAuthAttribute : ActionFilterAttribute
{
throw new SimApiException(401);
}
if (Types == null) return;
//检测用户类型
if (!Types.Intersect(loginInfo.Type).Any())
{