Files
simapi-net/Controllers/SimApiCommonController.cs
T

73 lines
1.9 KiB
C#
Raw Permalink Normal View History

2025-11-01 15:40:55 +08:00
using System.Collections.Generic;
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;
2025-11-01 15:40:55 +08:00
2024-03-23 07:29:43 +08:00
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>
2024-08-19 03:39:35 +08:00
[HttpPost, SimApiDoc("认证", "检测登陆")]
2024-03-23 07:29:43 +08:00
public SimApiBaseResponse<string> CheckLogin()
{
2025-11-01 15:40:55 +08:00
ErrorWhenNull(LoginInfo, 401, "未登录");
return new SimApiBaseResponse<string>
{
Data = LoginInfo.Id
};
2024-03-23 07:29:43 +08:00
}
/// <summary>
/// 退出登陆
/// </summary>
/// <returns></returns>
2024-08-19 03:39:35 +08:00
[HttpPost, SimApiDoc("认证", "退出登陆")]
2024-03-23 07:29:43 +08:00
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
}
auth.Logout(token!);
2024-03-23 07:29:43 +08:00
return new SimApiBaseResponse();
2020-07-05 06:09:02 +08:00
}
2024-08-19 03:39:35 +08:00
2025-11-01 15:40:55 +08:00
[HttpPost, HttpGet]
public SimApiBaseResponse<Dictionary<string, string>> Versions()
{
return new SimApiBaseResponse<Dictionary<string, string>>()
{
Data = new Dictionary<string, string>
{
{ "SimApi", SimApiUtil.SimApiVersion },
{ "App", SimApiUtil.AppVersion }
}
};
}
[HttpPost, SimApiAuth]
2024-06-27 04:38:04 +08:00
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
{
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
}
2021-05-30 03:35:27 +08:00
}