diff --git a/Controllers/YYBaseController.cs b/Controllers/YYBaseController.cs index 35d8ef9..261ebac 100644 --- a/Controllers/YYBaseController.cs +++ b/Controllers/YYBaseController.cs @@ -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 } /// - /// 错误回馈页面 + /// 上传文件 /// - /// 错误代码 /// - [HttpGet("exception/{code:int}")] - [ApiExplorerSettings(IgnoreApi = true)] - public YYBaseResponse ExceptionHandler(int code) - { - var response = new YYBaseResponse(); - response.SetCode(code); - return response; - } - protected YYBaseResponse UploadFile() { return new YYBaseResponse(); } + + } } \ No newline at end of file diff --git a/Controllers/YYCommonController.cs b/Controllers/YYCommonController.cs new file mode 100644 index 0000000..0929097 --- /dev/null +++ b/Controllers/YYCommonController.cs @@ -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; + } + + /// + /// 错误回馈页面 + /// + /// 错误代码 + /// + [HttpGet("exception/{code:int}")] + [ApiExplorerSettings(IgnoreApi = true)] + public YYBaseResponse ExceptionHandler(int code) + { + var response = new YYBaseResponse(); + response.SetCode(code); + return response; + } + + /// + /// 检测用户登陆的控制器 + /// + /// + [HttpPost("/auth/check"), YYDoc("认证", "检测登陆")] + public YYBaseResponse CheckLogin() + { + ErrorWhenNull(LoginInfo, 401); + return new YYBaseResponse { Data = LoginInfo.Id }; + } + + /// + /// 退出登陆 + /// + /// + [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(); + } + } +}