using System;
using Microsoft.AspNetCore.Mvc;
using SimApi.Attributes;
using SimApi.Communications;
using SimApi.Helpers;
namespace SimApi.Controllers
{
public class YYCommonController : SimApiBaseController
{
private SimApiAuth Auth { get; }
public YYCommonController(SimApiAuth auth)
{
Auth = auth;
}
///
/// 错误回馈页面
///
/// 错误代码
///
[HttpGet("exception/{code:int}")]
[ApiExplorerSettings(IgnoreApi = true)]
public SimApiBaseResponse ExceptionHandler(int code)
{
var response = new SimApiBaseResponse();
response.SetCode(code);
return response;
}
///
/// 检测用户登陆的控制器
///
///
[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.ContainsKey("Token"))
{
token = Request.Headers["Token"];
}
Auth.Logout(token);
return new SimApiBaseResponse();
}
}
}