diff --git a/Learn.Archives.API/Controllers/AdminController.cs b/Learn.Archives.API/Controllers/AdminController.cs index 3dbdccd..b3d5740 100644 --- a/Learn.Archives.API/Controllers/AdminController.cs +++ b/Learn.Archives.API/Controllers/AdminController.cs @@ -66,6 +66,7 @@ namespace Learn.Archives.API.Controllers AccessToken = JwtHelper.GetToken(AppCommon.Config.AuthKey, [ new Claim(ClaimEnum.Role,admin.RoleId.ToString()), + new Claim(ClaimEnum.UserId,admin.RoleId.ToString()), new Claim(ClaimEnum.Id, admin.Id.ToString()), new Claim(ClaimEnum.Name, admin.Name), ]) diff --git a/Learn.Archives.API/Controllers/ClassController.cs b/Learn.Archives.API/Controllers/ClassController.cs deleted file mode 100644 index ea43f1d..0000000 --- a/Learn.Archives.API/Controllers/ClassController.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Learn.Archives.API.Controllers.Dto; -using Learn.Archives.API.Expand; -using Learn.Archives.Core.Common; -using Learn.Archives.Core.Model; -using Learn.Archives.Core.Model.Dto; -using Mapster; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using System.Diagnostics; -using System.Security.Claims; -using UserCenter.Model; -using static System.Runtime.InteropServices.JavaScript.JSType; - -namespace Learn.Archives.API.Controllers -{ - /// - /// 班级控制器 - /// - public class ClassController : BackController - { - readonly Repository baseService; - readonly LiveUserInfo userInfo; - public ClassController(Repository baseService, LiveUserInfo userInfo) : base(baseService) - { - this.baseService = baseService; - this.userInfo = userInfo; - } - public override async Task PageList([FromBody] QueryRequestBase model) - { - var res = (PageResult) await base.PageList(model); - return new PageResult() { Data = res.Data.Adapt>(), Total = res.Total }; - } - } -} diff --git a/Learn.Archives.API/Controllers/SchoolController.cs b/Learn.Archives.API/Controllers/SchoolController.cs deleted file mode 100644 index 7701775..0000000 --- a/Learn.Archives.API/Controllers/SchoolController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Learn.Archives.API.Controllers.Dto; -using Learn.Archives.API.Expand; -using Learn.Archives.Core.Common; -using Learn.Archives.Core.Model; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using System.Diagnostics; -using System.Security.Claims; -using UserCenter.Model; - -namespace Learn.Archives.API.Controllers -{ - public class SchoolController : BackController - { - readonly Repository baseService; - public SchoolController(Repository baseService) : base(baseService) - { - this.baseService = baseService; - } - - public override Task Del([FromBody] params long[] ids) - { - return base.Del(ids); - } - } -} diff --git a/Learn.Archives.API/Controllers/_BaseController.cs b/Learn.Archives.API/Controllers/_BaseController.cs index 0a18f8b..88d3e04 100644 --- a/Learn.Archives.API/Controllers/_BaseController.cs +++ b/Learn.Archives.API/Controllers/_BaseController.cs @@ -45,7 +45,8 @@ namespace Learn.Archives.API.Controllers /// /// /// - [HttpGet] + [HttpGet()] + [Route("/api/[controller]/{id}")] public virtual async Task Info(long id) { return await _baseRepository.GetByIdAsync(id); @@ -139,8 +140,8 @@ namespace Learn.Archives.API.Controllers [HttpPost] public virtual async Task> QueryCombo([FromBody] QueryCombo model) { - if (string.IsNullOrEmpty(model.ValueName) || string.IsNullOrEmpty(model.TextName)) - Oh.ModelError("ValueName TextName 是必填项"); + //if (string.IsNullOrEmpty(model.ValueName) || string.IsNullOrEmpty(model.TextName)) + // Oh.ModelError("ValueName TextName 是必填项"); var sqlquery = BaseQuery(model); var res = await sqlquery.Select($"{model.TextName} as Text , {model.ValueName} as Value").ToListAsync(); return res; diff --git a/Learn.Archives.API/Expand/AuthorizeExpand.cs b/Learn.Archives.API/Expand/AuthorizeExpand.cs index 9008358..4beb4c3 100644 --- a/Learn.Archives.API/Expand/AuthorizeExpand.cs +++ b/Learn.Archives.API/Expand/AuthorizeExpand.cs @@ -20,6 +20,8 @@ namespace Learn.Archives.API.Expand { options.RequireHttpsMetadata = false; options.UseSecurityTokenValidators = true; + options.MapInboundClaims = false; // .NET 5+ + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); options.TokenValidationParameters = new TokenValidationParameters { SaveSigninToken = false,//保存token,后台验证token是否生效(重要) @@ -47,18 +49,14 @@ namespace Learn.Archives.API.Expand }, OnAuthenticationFailed = context => { - context.Response.Clear(); - context.Response.ContentType = "application/json"; context.Response.StatusCode = 403; - var data = new BaseReturn() { Code = 403, Message = context.Exception.Message + context.Exception?.StackTrace }; - context.Response.WriteAsync(data.ToJson()); return Task.CompletedTask; }, OnChallenge = context => { - if(context.Response.StatusCode == 403 || context.Response.StatusCode == 401) - return Task.CompletedTask; context.HandleResponse(); + if (context.Response.StatusCode == 403) + return Task.CompletedTask; context.Response.Clear(); context.Response.ContentType = "application/json"; context.Response.StatusCode = 401; diff --git a/Learn.Archives.API/Program.cs b/Learn.Archives.API/Program.cs index bdd7f8d..d21200e 100644 --- a/Learn.Archives.API/Program.cs +++ b/Learn.Archives.API/Program.cs @@ -55,9 +55,10 @@ app.UseRouting(); //Զ Ӧ app.UseCorsExpand(); +app.UseAuthorization(); + app.UseSqlSugarExpand(); -app.UseAuthorization(); app.MapControllers(); diff --git a/Learn.Archives.API/appsettings.json b/Learn.Archives.API/appsettings.json index 2b7ae8b..d3ddfa0 100644 --- a/Learn.Archives.API/appsettings.json +++ b/Learn.Archives.API/appsettings.json @@ -17,7 +17,7 @@ "UpdateTable": false }, "AuthKey": { - "Secret": "9FAB7AC7-F2DB-4C52-B81F-044055A34AF2", + "Secret": "9FAB7AC7-F1DB-4C56-B84F-044055A34AF2", "Issuer": "Learn.Archive", //签发人 "Audience": "Admin", "Expires": 120 // 过期时间120小时 diff --git a/Learn.Archives.Core/Common/AppConfig.cs b/Learn.Archives.Core/Common/AppConfig.cs index c3aada0..544d712 100644 --- a/Learn.Archives.Core/Common/AppConfig.cs +++ b/Learn.Archives.Core/Common/AppConfig.cs @@ -70,8 +70,22 @@ namespace Learn.Archives.Core.Common /// public SimpLetexConfig SimpLetex { get; set; } = new SimpLetexConfig(); - } + /// + /// 用户中心服务配置 + /// + public UserCenterServiceConfig UserCenterService { get; set; } = new UserCenterServiceConfig(); + } + /// + /// 用户中心服务配置 + /// + public class UserCenterServiceConfig + { + /// + /// api请求地址 + /// + public string API { get; set; } + } public class AuthKeyConfig { /// diff --git a/Learn.Archives.Core/Common/AuthenticationSchemes.cs b/Learn.Archives.Core/Common/AuthenticationSchemes.cs index b487679..4f36af1 100644 --- a/Learn.Archives.Core/Common/AuthenticationSchemes.cs +++ b/Learn.Archives.Core/Common/AuthenticationSchemes.cs @@ -8,6 +8,6 @@ namespace Learn.Archives.Core.Common { public class Authentication { - public const string Admin = "Admin"; + public const string Admin = "admin"; } } diff --git a/Learn.Archives.Core/Common/ClaimEnum.cs b/Learn.Archives.Core/Common/ClaimEnum.cs index 51339de..e456ae0 100644 --- a/Learn.Archives.Core/Common/ClaimEnum.cs +++ b/Learn.Archives.Core/Common/ClaimEnum.cs @@ -6,7 +6,7 @@ public static string PositionId => "position"; public static string UserId => "user"; public static string Id => "id"; - public static string Role => "roleid"; + public static string Role => "role"; public static string Scope => "scope"; public static string Name => "name"; } diff --git a/Learn.Archives.Core/Learn.Archives.Core.csproj b/Learn.Archives.Core/Learn.Archives.Core.csproj index 3541293..50292c9 100644 --- a/Learn.Archives.Core/Learn.Archives.Core.csproj +++ b/Learn.Archives.Core/Learn.Archives.Core.csproj @@ -26,6 +26,7 @@ + diff --git a/Learn.Archives.Core/Model/Dto/QueryRequestBase.cs b/Learn.Archives.Core/Model/Dto/QueryRequestBase.cs index 49989d2..2d3cc54 100644 --- a/Learn.Archives.Core/Model/Dto/QueryRequestBase.cs +++ b/Learn.Archives.Core/Model/Dto/QueryRequestBase.cs @@ -45,13 +45,13 @@ namespace Learn.Archives.Core.Model.Dto /// /// 值对应属性名称 /// - [Required(ErrorMessage = "{0}是必填项")] - public string ValueName { get; set; } + [Required(ErrorMessage = "{0}是必填项")] + public string ValueName { get; set; } = "Id"; /// /// 文本对应属性名称 /// [Required(ErrorMessage = "{0}是必填项")] - public string TextName { get; set; } + public string TextName { get; set; } = "Name"; } /// diff --git a/Learn.Archives.Core/Model/Grade.cs b/Learn.Archives.Core/Model/Grade.cs index fdd5e1c..bde757d 100644 --- a/Learn.Archives.Core/Model/Grade.cs +++ b/Learn.Archives.Core/Model/Grade.cs @@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations; using System.Net; using System.Text.Json; using UserCenter.Model; +using UserCenter.Model.Common; using UserCenter.Model.Enum; using UserCenter.Model.Interface; @@ -26,6 +27,11 @@ namespace Learn.Archives.Core.Model [SugarColumn(Length = 6)] public int Year { get; set; } /// + /// 年级名称 + /// + [SugarColumn(IsIgnore =true)] + public string Name => GradeHelper.GetGrade(Level.ToString(), Year); + /// /// 学校名称 /// [SugarColumn(Length = 12)]