add CoceLoginProcessor

This commit is contained in:
2025-01-17 01:30:13 +08:00
parent afea9c82bd
commit 4ae72d2e6b
4 changed files with 44 additions and 27 deletions
@@ -1,14 +1,16 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using SimApi.Attributes; using SimApi.Attributes;
using SimApi.CoceSdk;
using SimApi.Communications; using SimApi.Communications;
using SimApi.Controllers;
using SimApi.Helpers; using SimApi.Helpers;
namespace SimApi.Controllers; namespace SimApi.CoceSdk;
public class SimApiCoceController(CoceApp coce,SimApiAuth auth) : SimApiBaseController public class CoceController(CoceApp coce, SimApiAuth auth, IServiceProvider sp) : SimApiBaseController
{ {
[HttpPost] [HttpPost]
public SimApiBaseResponse<ConfigResponse> GetConfig() public SimApiBaseResponse<ConfigResponse> GetConfig()
@@ -33,8 +35,9 @@ public class SimApiCoceController(CoceApp coce,SimApiAuth auth) : SimApiBaseCont
{ {
Id = data.UserId, Id = data.UserId,
Meta = meta, Meta = meta,
Extra = groups
}; };
var processor = sp.GetService<ICoceLoginProcessor>();
processor?.Process(loginItem, groups.ToArray());
return new SimApiBaseResponse<string>(auth.Login(loginItem)); return new SimApiBaseResponse<string>(auth.Login(loginItem));
} }
+9
View File
@@ -0,0 +1,9 @@
using System.Collections.Generic;
using SimApi.Communications;
namespace SimApi.CoceSdk;
public interface ICoceLoginProcessor
{
SimApiLoginItem Process(SimApiLoginItem loginItem, GroupInfo[] groups);
}
+22 -19
View File
@@ -10,13 +10,7 @@ public class SimApiOptions
/// <summary> /// <summary>
/// 是否启用后台任务系统 *基于Hangfire /// 是否启用后台任务系统 *基于Hangfire
/// </summary> /// </summary>
public bool EnableJob { get; set; } = false; public bool EnableJob { get; set; }
/// <summary>
/// 启用全部Cors,对于开发前后分离的时候很有用。
/// default: true
/// </summary>
public bool EnableCors { get; set; } = true;
/// <summary> /// <summary>
/// 启用SimApiAuth,一个简单的基于Header Token的认证方式。 /// 启用SimApiAuth,一个简单的基于Header Token的认证方式。
@@ -24,13 +18,16 @@ public class SimApiOptions
/// </summary> /// </summary>
public bool EnableSimApiAuth { get; set; } public bool EnableSimApiAuth { get; set; }
/// <summary> /// <summary>
/// 是否使用CoceSdk /// 是否使用CoceSdk
/// </summary> /// </summary>
public bool EnableCoceSdk { get; set; } public bool EnableCoceSdk { get; set; }
public CoceAppSdkOption CoceSdkOptions { get; set; } = new(); /// <summary>
/// 开启S3兼容的存储系统。
/// default: false
/// </summary>
public bool EnableSimApiStorage { get; set; }
/// <summary> /// <summary>
/// 启用在线文档,启用后 访问 /swagger 可以查看对应的api文档。 /// 启用在线文档,启用后 访问 /swagger 可以查看对应的api文档。
@@ -38,6 +35,20 @@ public class SimApiOptions
/// </summary> /// </summary>
public bool EnableSimApiDoc { get; set; } public bool EnableSimApiDoc { get; set; }
/// <summary>
/// 是否启用Synapse
/// </summary>
public bool EnableSynapse { get; set; }
/// <summary>
/// 启用全部Cors,对于开发前后分离的时候很有用。
/// default: true
/// </summary>
public bool EnableCors { get; set; } = true;
public CoceAppSdkOption CoceSdkOptions { get; set; } = new();
/// <summary> /// <summary>
/// 启用异常拦截,启用后,所有的异常将被通过json反馈。 /// 启用异常拦截,启用后,所有的异常将被通过json反馈。
/// default: true /// default: true
@@ -49,11 +60,6 @@ public class SimApiOptions
/// </summary> /// </summary>
public bool EnableSimApiResponseFilter { get; set; } = true; public bool EnableSimApiResponseFilter { get; set; } = true;
/// <summary>
/// 开启S3兼容的存储系统。
/// default: false
/// </summary>
public bool EnableSimApiStorage { get; set; }
/// <summary> /// <summary>
/// 开启ForwardHeaders,开启后可以透传负载均衡的Headers /// 开启ForwardHeaders,开启后可以透传负载均衡的Headers
@@ -67,16 +73,13 @@ public class SimApiOptions
/// </summary> /// </summary>
public bool EnableLowerUrl { get; set; } = true; public bool EnableLowerUrl { get; set; } = true;
/// <summary> /// <summary>
/// 启用格式化的 Console Logger /// 启用格式化的 Console Logger
/// default: false /// default: false
/// </summary> /// </summary>
public bool EnableLogger { get; set; } public bool EnableLogger { get; set; } = true;
/// <summary>
/// 是否启用Synapse
/// </summary>
public bool EnableSynapse { get; set; }
/// <summary> /// <summary>
/// 配置Job /// 配置Job
+5 -3
View File
@@ -246,6 +246,7 @@ public static class SimApiExtensions
if (simApiOptions.EnableSimApiResponseFilter) if (simApiOptions.EnableSimApiResponseFilter)
{ {
builder.AddControllers(opt => opt.Filters.Add<SimApiResponseFilter>()) builder.AddControllers(opt => opt.Filters.Add<SimApiResponseFilter>())
.AddXmlSerializerFormatters()
.AddJsonOptions(opt => opt.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase); .AddJsonOptions(opt => opt.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase);
} }
@@ -319,6 +320,7 @@ public static class SimApiExtensions
if (options.EnableSimApiResponseFilter) if (options.EnableSimApiResponseFilter)
{ {
logger.LogInformation("开始配置SimApiResponseFilter..."); logger.LogInformation("开始配置SimApiResponseFilter...");
builder.MapControllers();
} }
if (options.EnableSimApiAuth) if (options.EnableSimApiAuth)
@@ -337,11 +339,11 @@ public static class SimApiExtensions
options.CoceSdkOptions.ApiEndpoint, options.CoceSdkOptions.AuthEndpoint, options.CoceSdkOptions.ApiEndpoint, options.CoceSdkOptions.AuthEndpoint,
options.CoceSdkOptions.AppId); options.CoceSdkOptions.AppId);
builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/login", builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/login",
defaults: new { controller = "SimApiCoce", action = "Login" }); defaults: new { controller = "Coce", action = "Login" });
builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/user/groups", builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/user/groups",
defaults: new { controller = "SimApiCoce", action = "ListGroups" }); defaults: new { controller = "Coce", action = "ListGroups" });
builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/config", builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/config",
defaults: new { controller = "SimApiCoce", action = "GetConfig" }); defaults: new { controller = "Coce", action = "GetConfig" });
} }
} }