Skip to content

Commit 9a8d141

Browse files
committed
version move to common
1 parent cb89a1a commit 9a8d141

File tree

3 files changed

+55
-43
lines changed

3 files changed

+55
-43
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections.Generic;
2+
using Microsoft.AspNetCore.Mvc;
3+
using SimApi.Attributes;
4+
using SimApi.Communications;
5+
using SimApi.Helpers;
6+
7+
namespace SimApi.Controllers;
8+
9+
public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController
10+
{
11+
/// <summary>
12+
/// 检测用户登陆的控制器
13+
/// </summary>
14+
/// <returns></returns>
15+
[HttpPost, SimApiDoc("认证", "检测登陆")]
16+
public SimApiBaseResponse<string> CheckLogin()
17+
{
18+
ErrorWhenNull(LoginInfo, 401, "未登录");
19+
return new SimApiBaseResponse<string>
20+
{
21+
Data = LoginInfo.Id
22+
};
23+
}
24+
25+
/// <summary>
26+
/// 退出登陆
27+
/// </summary>
28+
/// <returns></returns>
29+
[HttpPost, SimApiDoc("认证", "退出登陆")]
30+
public SimApiBaseResponse Logout()
31+
{
32+
string? token = null;
33+
34+
if (Request.Headers.TryGetValue("Token", out var value))
35+
{
36+
token = value;
37+
}
38+
39+
auth.Logout(token!);
40+
return new SimApiBaseResponse();
41+
}
42+
43+
44+
[HttpPost, SimApiAuth]
45+
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
46+
{
47+
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
48+
}
49+
}
Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using Microsoft.AspNetCore.Mvc;
3-
using SimApi.Attributes;
43
using SimApi.Communications;
54
using SimApi.Helpers;
65

76
namespace SimApi.Controllers;
87

9-
public class SimApiCommonController(SimApiAuth auth) : SimApiBaseController
8+
public class SimApiCommonController : SimApiBaseController
109
{
1110
/// <summary>
1211
/// 错误回馈页面
@@ -20,37 +19,6 @@ public SimApiBaseResponse ExceptionHandler(int code)
2019
return new SimApiBaseResponse(code);
2120
}
2221

23-
/// <summary>
24-
/// 检测用户登陆的控制器
25-
/// </summary>
26-
/// <returns></returns>
27-
[HttpPost, SimApiDoc("认证", "检测登陆")]
28-
public SimApiBaseResponse<string> CheckLogin()
29-
{
30-
ErrorWhenNull(LoginInfo, 401, "未登录");
31-
return new SimApiBaseResponse<string>
32-
{
33-
Data = LoginInfo.Id
34-
};
35-
}
36-
37-
/// <summary>
38-
/// 退出登陆
39-
/// </summary>
40-
/// <returns></returns>
41-
[HttpPost, SimApiDoc("认证", "退出登陆")]
42-
public SimApiBaseResponse Logout()
43-
{
44-
string? token = null;
45-
46-
if (Request.Headers.TryGetValue("Token", out var value))
47-
{
48-
token = value;
49-
}
50-
51-
auth.Logout(token!);
52-
return new SimApiBaseResponse();
53-
}
5422

5523
[HttpPost, HttpGet]
5624
public SimApiBaseResponse<Dictionary<string, string>> Versions()
@@ -64,10 +32,4 @@ public SimApiBaseResponse<Dictionary<string, string>> Versions()
6432
}
6533
};
6634
}
67-
68-
[HttpPost, SimApiAuth]
69-
public SimApiBaseResponse<SimApiLoginItem> UserInfo()
70-
{
71-
return new SimApiBaseResponse<SimApiLoginItem>(LoginInfo);
72-
}
7335
}

SimApiExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public static IServiceCollection AddSimApi(this IServiceCollection builder,
141141
{
142142
return docName == "api"; // 未分组接口只属于默认分组v1
143143
}
144+
144145
return docName == actionGroupName;
145146
});
146147

@@ -324,19 +325,19 @@ public static WebApplication UseSimApi(this WebApplication builder)
324325
builder.MapControllerRoute(name: "GetUserInfo", pattern: "/user/info",
325326
defaults: new
326327
{
327-
controller = "SimApiCommon",
328+
controller = "SimApiAuth",
328329
action = "UserInfo"
329330
});
330331
builder.MapControllerRoute(name: "CheckLogin", pattern: "/auth/check",
331332
defaults: new
332333
{
333-
controller = "SimApiCommon",
334+
controller = "SimApiAuth",
334335
action = "CheckLogin"
335336
});
336337
builder.MapControllerRoute(name: "Logout", pattern: "/auth/logout",
337338
defaults: new
338339
{
339-
controller = "SimApiCommon",
340+
controller = "SimApiAuth",
340341
action = "Logout"
341342
});
342343
if (options.EnableCoceSdk)

0 commit comments

Comments
 (0)