diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index e9527636..4fda8ac8 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -110,7 +110,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task GetUserAllInfo() { //通过鉴权jwt获取到用户的id - var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id; + var userId = HttpContext.GetUserIdInfo(); var data = await _iUserService.GetUserAllInfo(userId); data.Menus.Clear(); return Result.Success().SetData(data); @@ -123,7 +123,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpGet] public async Task GetRouterInfo() { - var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id; + var userId = HttpContext.GetUserIdInfo(); var data = await _iUserService.GetUserAllInfo(userId); //将后端菜单转换成前端路由,组件级别需要过滤 @@ -144,7 +144,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers user.Salt = null; //修改需要赋值上主键哦 - user.Id = HttpContext.GetCurrentUserEntityInfo(out _).Id; + user.Id = HttpContext.GetUserIdInfo(); return Result.Success().SetStatus(await _iUserService._repository.UpdateIgnoreNullAsync(user)); } @@ -156,7 +156,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPut] public async Task UpdatePassword(UpdatePasswordDto dto) { - long userId = HttpContext.GetCurrentUserEntityInfo(out _).Id; + long userId = HttpContext.GetUserIdInfo(); if (await _iUserService.UpdatePassword(dto, userId)) { diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs index a7a81169..7f8a1214 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs @@ -26,13 +26,19 @@ namespace Yi.Framework.WebCore return "XMLHttpRequest".Equals(header); } + + public static long GetUserIdInfo(this HttpContext httpContext) + { + return Convert.ToInt64(httpContext.User.Claims.FirstOrDefault(u => u.Type== JwtRegisteredClaimNames.Sid)); + } + /// /// 基于HttpContext,当前鉴权方式解析,获取用户信息 /// 现在使用redis作为缓存,不需要将菜单存放至jwt中了 /// /// /// - public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List menuIds) + public static UserEntity GetUserEntityInfo(this HttpContext httpContext, out List menuIds) { IEnumerable claimlist = null; long resId = 0;