version move to common
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SimApi.Attributes;
|
||||||
|
using SimApi.Communications;
|
||||||
|
using SimApi.Helpers;
|
||||||
|
|
||||||
|
namespace SimApi.Controllers;
|
||||||
|
|
||||||
|
public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 检测用户登陆的控制器
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost, SimApiDoc("认证", "检测登陆")]
|
||||||
|
public SimApiBaseResponse<string> CheckLogin()
|
||||||
|
{
|
||||||
|
ErrorWhenNull(LoginInfo, 401, "未登录");
|
||||||
|
return new SimApiBaseResponse<string>
|
||||||
|
{
|
||||||
|
Data = LoginInfo.Id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 退出登陆
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost, SimApiDoc("认证", "退出登陆")]
|
||||||
|
public SimApiBaseResponse Logout()
|
||||||
|
{
|
||||||
|
string? token = null;
|
||||||
|
|
||||||
|
if (Request.Headers.TryGetValue("Token", out var value))
|
||||||
|
{
|
||||||
|
token = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
auth.Logout(token!);
|
||||||
|
return new SimApiBaseResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost, SimApiAuth]
|
||||||
|
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
|
||||||
|
{
|
||||||
|
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SimApi.Attributes;
|
|
||||||
using SimApi.Communications;
|
using SimApi.Communications;
|
||||||
using SimApi.Helpers;
|
using SimApi.Helpers;
|
||||||
|
|
||||||
namespace SimApi.Controllers;
|
namespace SimApi.Controllers;
|
||||||
|
|
||||||
public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
|
public class SimApiCommonController : SimApiBaseController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 错误回馈页面
|
/// 错误回馈页面
|
||||||
@@ -20,37 +19,6 @@ public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
|
|||||||
return new SimApiBaseResponse(code);
|
return new SimApiBaseResponse(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测用户登陆的控制器
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost, SimApiDoc("认证", "检测登陆")]
|
|
||||||
public SimApiBaseResponse<string> CheckLogin()
|
|
||||||
{
|
|
||||||
ErrorWhenNull(LoginInfo, 401, "未登录");
|
|
||||||
return new SimApiBaseResponse<string>
|
|
||||||
{
|
|
||||||
Data = LoginInfo.Id
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 退出登陆
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost, SimApiDoc("认证", "退出登陆")]
|
|
||||||
public SimApiBaseResponse Logout()
|
|
||||||
{
|
|
||||||
string? token = null;
|
|
||||||
|
|
||||||
if (Request.Headers.TryGetValue("Token", out var value))
|
|
||||||
{
|
|
||||||
token = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
auth.Logout(token!);
|
|
||||||
return new SimApiBaseResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost, HttpGet]
|
[HttpPost, HttpGet]
|
||||||
public SimApiBaseResponse<Dictionary<string, string>> Versions()
|
public SimApiBaseResponse<Dictionary<string, string>> Versions()
|
||||||
@@ -64,10 +32,4 @@ public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, SimApiAuth]
|
|
||||||
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
|
|
||||||
{
|
|
||||||
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+4
-3
@@ -141,6 +141,7 @@ public static class SimApiExtensions
|
|||||||
{
|
{
|
||||||
return docName == "api"; // 未分组接口只属于默认分组v1
|
return docName == "api"; // 未分组接口只属于默认分组v1
|
||||||
}
|
}
|
||||||
|
|
||||||
return docName == actionGroupName;
|
return docName == actionGroupName;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -324,19 +325,19 @@ public static class SimApiExtensions
|
|||||||
builder.MapControllerRoute(name: "GetUserInfo", pattern: "/user/info",
|
builder.MapControllerRoute(name: "GetUserInfo", pattern: "/user/info",
|
||||||
defaults: new
|
defaults: new
|
||||||
{
|
{
|
||||||
controller = "SimApiCommon",
|
controller = "SimApiAuth",
|
||||||
action = "UserInfo"
|
action = "UserInfo"
|
||||||
});
|
});
|
||||||
builder.MapControllerRoute(name: "CheckLogin", pattern: "/auth/check",
|
builder.MapControllerRoute(name: "CheckLogin", pattern: "/auth/check",
|
||||||
defaults: new
|
defaults: new
|
||||||
{
|
{
|
||||||
controller = "SimApiCommon",
|
controller = "SimApiAuth",
|
||||||
action = "CheckLogin"
|
action = "CheckLogin"
|
||||||
});
|
});
|
||||||
builder.MapControllerRoute(name: "Logout", pattern: "/auth/logout",
|
builder.MapControllerRoute(name: "Logout", pattern: "/auth/logout",
|
||||||
defaults: new
|
defaults: new
|
||||||
{
|
{
|
||||||
controller = "SimApiCommon",
|
controller = "SimApiAuth",
|
||||||
action = "Logout"
|
action = "Logout"
|
||||||
});
|
});
|
||||||
if (options.EnableCoceSdk)
|
if (options.EnableCoceSdk)
|
||||||
|
|||||||
Reference in New Issue
Block a user