Compare commits

..
1 Commits
Author SHA1 Message Date
xrain 31df4a7593 add auth check 2020-07-05 06:09:02 +08:00
2 changed files with 64 additions and 11 deletions
+4 -11
View File
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.Linq;
using YYApi.Exceptions;
using YYApi.Attributes;
namespace YYApi.Controllers
{
@@ -77,22 +78,14 @@ namespace YYApi.Controllers
}
/// <summary>
/// 错误回馈页面
/// 上传文件
/// </summary>
/// <param name="code">错误代码</param>
/// <returns></returns>
[HttpGet("exception/{code:int}")]
[ApiExplorerSettings(IgnoreApi = true)]
public YYBaseResponse ExceptionHandler(int code)
{
var response = new YYBaseResponse();
response.SetCode(code);
return response;
}
protected YYBaseResponse<string> UploadFile()
{
return new YYBaseResponse<string>();
}
}
}
+60
View File
@@ -0,0 +1,60 @@
using System;
using Microsoft.AspNetCore.Mvc;
using YYApi.Attributes;
using YYApi.Communications;
using YYApi.Helpers;
namespace YYApi.Controllers
{
public class YYCommonController : YYBaseController
{
private YYAuth Auth { get; }
public YYCommonController(YYAuth auth)
{
Auth = auth;
}
/// <summary>
/// 错误回馈页面
/// </summary>
/// <param name="code">错误代码</param>
/// <returns></returns>
[HttpGet("exception/{code:int}")]
[ApiExplorerSettings(IgnoreApi = true)]
public YYBaseResponse ExceptionHandler(int code)
{
var response = new YYBaseResponse();
response.SetCode(code);
return response;
}
/// <summary>
/// 检测用户登陆的控制器
/// </summary>
/// <returns></returns>
[HttpPost("/auth/check"), YYDoc("认证", "检测登陆")]
public YYBaseResponse<int> CheckLogin()
{
ErrorWhenNull(LoginInfo, 401);
return new YYBaseResponse<int> { Data = LoginInfo.Id };
}
/// <summary>
/// 退出登陆
/// </summary>
/// <returns></returns>
[HttpPost("/auth/logout"), YYDoc("认证", "退出登陆")]
public YYBaseResponse Logout()
{
string token = null;
if (Request.Headers.ContainsKey("Token"))
{
token = Request.Headers["Token"];
}
Auth.Logout(token);
return new YYBaseResponse();
}
}
}