using Microsoft.AspNetCore.Mvc;
using SimApi.Attributes;
using SimApi.Communications;
using SimApi.Helpers;
namespace SimApi.Controllers;
[ApiExplorerSettings(GroupName = "api")]
public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
{
///
/// 错误回馈页面
///
/// 错误代码
///
[HttpGet("exception/{code:int}")]
[ApiExplorerSettings(IgnoreApi = true)]
public SimApiBaseResponse ExceptionHandler(int code)
{
return new SimApiBaseResponse(code);
}
///
/// 检测用户登陆的控制器
///
///
[HttpPost("/auth/check"), SimApiDoc("认证", "检测登陆")]
public SimApiBaseResponse CheckLogin()
{
ErrorWhenNull(LoginInfo, 401);
return new SimApiBaseResponse
{
Data = LoginInfo.Id
};
}
///
/// 退出登陆
///
///
[HttpPost("/auth/logout"), SimApiDoc("认证", "退出登陆")]
public SimApiBaseResponse Logout()
{
string? token = null;
if (Request.Headers.TryGetValue("Token", out var value))
{
token = value;
}
auth.Logout(token!);
return new SimApiBaseResponse();
}
[HttpPost("/logined"),SimApiAuth]
public SimApiBaseResponse UserInfo()
{
return new SimApiBaseResponse(LoginInfo);
}
}