From 52b8bc8909b339730006582c3f8752808f26635c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Thu, 15 Sep 2022 18:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7id=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 8 ++++---- Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) 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;