Files
simapi-net/Controllers/SimApiCommonController.cs
T

65 lines
1.7 KiB
C#
Raw Normal View History

2020-07-05 06:09:02 +08:00
using System;
using Microsoft.AspNetCore.Mvc;
2020-08-05 15:29:56 +08:00
using SimApi.Attributes;
using SimApi.Communications;
using SimApi.Helpers;
2020-07-05 06:09:02 +08:00
2020-08-05 15:29:56 +08:00
namespace SimApi.Controllers
2020-07-05 06:09:02 +08:00
{
2021-05-30 03:35:27 +08:00
[ApiExplorerSettings(GroupName = "api")]
2020-08-05 15:29:56 +08:00
public class YYCommonController : SimApiBaseController
2020-07-05 06:09:02 +08:00
{
2020-08-05 15:29:56 +08:00
private SimApiAuth Auth { get; }
2020-07-05 06:09:02 +08:00
2020-08-05 15:29:56 +08:00
public YYCommonController(SimApiAuth auth)
2020-07-05 06:09:02 +08:00
{
Auth = auth;
}
/// <summary>
/// 错误回馈页面
/// </summary>
/// <param name="code">错误代码</param>
/// <returns></returns>
[HttpGet("exception/{code:int}")]
[ApiExplorerSettings(IgnoreApi = true)]
2020-08-05 15:29:56 +08:00
public SimApiBaseResponse ExceptionHandler(int code)
2020-07-05 06:09:02 +08:00
{
2020-08-05 15:29:56 +08:00
var response = new SimApiBaseResponse();
2020-07-05 06:09:02 +08:00
response.SetCode(code);
return response;
}
/// <summary>
/// 检测用户登陆的控制器
/// </summary>
/// <returns></returns>
2020-08-05 15:29:56 +08:00
[HttpPost("/auth/check"), SimApiDoc("认证", "检测登陆")]
2022-05-07 21:30:45 +08:00
public SimApiBaseResponse<string> CheckLogin()
2020-07-05 06:09:02 +08:00
{
ErrorWhenNull(LoginInfo, 401);
2022-05-07 21:30:45 +08:00
return new SimApiBaseResponse<string>
{
Data = LoginInfo.Id
};
2020-07-05 06:09:02 +08:00
}
/// <summary>
/// 退出登陆
/// </summary>
/// <returns></returns>
2020-08-05 15:29:56 +08:00
[HttpPost("/auth/logout"), SimApiDoc("认证", "退出登陆")]
public SimApiBaseResponse Logout()
2020-07-05 06:09:02 +08:00
{
string token = null;
if (Request.Headers.ContainsKey("Token"))
{
token = Request.Headers["Token"];
}
2021-05-30 03:35:27 +08:00
2020-07-05 06:09:02 +08:00
Auth.Logout(token);
2020-08-05 15:29:56 +08:00
return new SimApiBaseResponse();
2020-07-05 06:09:02 +08:00
}
}
2021-05-30 03:35:27 +08:00
}