Files
simapi-net/Controllers/SimApiCommonController.cs
T

54 lines
1.4 KiB
C#
Raw Normal View History

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);
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()
{
string token = null;
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
}
auth.Logout(token!);
2024-03-23 07:29:43 +08:00
return new SimApiBaseResponse();
2020-07-05 06:09:02 +08:00
}
2021-05-30 03:35:27 +08:00
}