fix name policy
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using YYApi.Communications;
|
||||
using YYApi.Exceptions;
|
||||
|
||||
namespace YYApi.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// 检测登录中间件
|
||||
/// </summary>
|
||||
public class YYAuthAttribute : ActionFilterAttribute
|
||||
{
|
||||
private string[] Types { get; }
|
||||
|
||||
//默认是user登录类型
|
||||
public YYAuthAttribute()
|
||||
{
|
||||
Types = new[] { "user" };
|
||||
}
|
||||
|
||||
//只检测一种用户类型的快捷方式
|
||||
public YYAuthAttribute(string type)
|
||||
{
|
||||
Types = new[] { type };
|
||||
}
|
||||
|
||||
//设定特定类型的检测
|
||||
public YYAuthAttribute(string[] types)
|
||||
{
|
||||
Types = types;
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var loginInfo = (YYLoginItem)context.HttpContext.Items["LoginInfo"];
|
||||
//检测是否登录
|
||||
if (loginInfo == null)
|
||||
{
|
||||
throw new YYApiException(401);
|
||||
}
|
||||
//检测用户类型
|
||||
if (!Types.Contains(loginInfo.Type))
|
||||
{
|
||||
throw new YYApiException(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace YYApi.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// 快捷自定义接口文档类
|
||||
/// </summary>
|
||||
public class YYDocAttribute : SwaggerOperationAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义接口说明
|
||||
/// </summary>
|
||||
/// <param name="tag">接口分组</param>
|
||||
/// <param name="name">接口名称</param>
|
||||
public YYDocAttribute(string tag, string name)
|
||||
{
|
||||
Tags = new[] { tag };
|
||||
Summary = name;
|
||||
// Consumes = new[] {"application/json"};
|
||||
// Produces = new[] {"application/json"};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user