2024-03-23 07:29:43 +08:00
|
|
|
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
|
|
|
|
2024-03-23 07:29:43 +08:00
|
|
|
namespace SimApi.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(GroupName = "api")]
|
|
|
|
|
public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
|
2020-07-05 06:09:02 +08:00
|
|
|
{
|
2024-03-23 07:29:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 错误回馈页面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="code">错误代码</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("exception/{code:int}")]
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public SimApiBaseResponse ExceptionHandler(int code)
|
2020-07-05 06:09:02 +08:00
|
|
|
{
|
2024-03-23 07:29:43 +08:00
|
|
|
return new SimApiBaseResponse(code);
|
|
|
|
|
}
|
2020-07-05 06:09:02 +08:00
|
|
|
|
2024-03-23 07:29:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 检测用户登陆的控制器
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/auth/check"), SimApiDoc("认证", "检测登陆")]
|
|
|
|
|
public SimApiBaseResponse<string> CheckLogin()
|
|
|
|
|
{
|
|
|
|
|
ErrorWhenNull(LoginInfo, 401);
|
2024-04-16 06:29:21 +08:00
|
|
|
return new SimApiBaseResponse<string>
|
|
|
|
|
{
|
|
|
|
|
Data = LoginInfo.Id
|
|
|
|
|
};
|
2024-03-23 07:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 退出登陆
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/auth/logout"), SimApiDoc("认证", "退出登陆")]
|
|
|
|
|
public SimApiBaseResponse Logout()
|
|
|
|
|
{
|
2024-07-26 08:11:21 +08:00
|
|
|
string? token = null;
|
2024-03-23 07:29:43 +08:00
|
|
|
|
2024-03-23 07:30:24 +08:00
|
|
|
if (Request.Headers.TryGetValue("Token", out var value))
|
2020-07-05 06:09:02 +08:00
|
|
|
{
|
2024-03-23 07:30:24 +08:00
|
|
|
token = value;
|
2020-07-05 06:09:02 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-16 06:29:21 +08:00
|
|
|
auth.Logout(token!);
|
2024-03-23 07:29:43 +08:00
|
|
|
return new SimApiBaseResponse();
|
2020-07-05 06:09:02 +08:00
|
|
|
}
|
2024-06-27 04:38:04 +08:00
|
|
|
|
|
|
|
|
[HttpPost("/logined"),SimApiAuth]
|
|
|
|
|
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
|
|
|
|
|
{
|
|
|
|
|
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
|
|
|
|
|
}
|
2021-05-30 03:35:27 +08:00
|
|
|
}
|