22using System . Collections . Generic ;
33using System . Linq ;
44using System . Threading . Tasks ;
5+ using Blog . Core . AuthHelper . OverWrite ;
56using Blog . Core . Common . Helper ;
67using Blog . Core . IServices ;
78using Blog . Core . Model ;
89using Blog . Core . Model . Models ;
910using Microsoft . AspNetCore . Authorization ;
11+ using Microsoft . AspNetCore . Http ;
1012using Microsoft . AspNetCore . Mvc ;
1113
1214namespace Blog . Core . Controllers
@@ -23,6 +25,7 @@ public class PermissionController : ControllerBase
2325 readonly IModuleServices _moduleServices ;
2426 readonly IRoleModulePermissionServices _roleModulePermissionServices ;
2527 readonly IUserRoleServices _userRoleServices ;
28+ readonly IHttpContextAccessor _httpContext ;
2629
2730 /// <summary>
2831 /// 构造函数
@@ -31,12 +34,14 @@ public class PermissionController : ControllerBase
3134 /// <param name="moduleServices"></param>
3235 /// <param name="roleModulePermissionServices"></param>
3336 /// <param name="userRoleServices"></param>
34- public PermissionController ( IPermissionServices permissionServices , IModuleServices moduleServices , IRoleModulePermissionServices roleModulePermissionServices , IUserRoleServices userRoleServices )
37+ /// <param name="httpContext"></param>
38+ public PermissionController ( IPermissionServices permissionServices , IModuleServices moduleServices , IRoleModulePermissionServices roleModulePermissionServices , IUserRoleServices userRoleServices , IHttpContextAccessor httpContext )
3539 {
3640 _permissionServices = permissionServices ;
3741 _moduleServices = moduleServices ;
3842 _roleModulePermissionServices = roleModulePermissionServices ;
3943 _userRoleServices = userRoleServices ;
44+ _httpContext = httpContext ;
4045
4146 }
4247
@@ -114,7 +119,7 @@ public async Task<MessageModel<PageModel<Permission>>> Get(int page = 1, string
114119 }
115120
116121 permissions . data = permissionsView ;
117-
122+
118123 #endregion
119124
120125
@@ -263,12 +268,19 @@ orderby child.Id
263268 /// <param name="uid"></param>
264269 /// <returns></returns>
265270 [ HttpGet ]
266- [ AllowAnonymous ]
267271 public async Task < MessageModel < NavigationBar > > GetNavigationBar ( int uid )
268272 {
273+
269274 var data = new MessageModel < NavigationBar > ( ) ;
270275
271- if ( uid > 0 )
276+ // 两种方式获取 uid
277+ var uidInHttpcontext1 = ( from item in _httpContext . HttpContext . User . Claims
278+ where item . Type == "jti"
279+ select item . Value ) . FirstOrDefault ( ) . ObjToInt ( ) ;
280+
281+ var uidInHttpcontext = ( JwtHelper . SerializeJwt ( _httpContext . HttpContext . Request . Headers [ "Authorization" ] . ObjToString ( ) . Replace ( "Bearer " , "" ) ) ) ? . Uid ;
282+
283+ if ( uid > 0 && uid == uidInHttpcontext )
272284 {
273285 var roleId = ( ( await _userRoleServices . Query ( d => d . IsDeleted == false && d . UserId == uid ) ) . FirstOrDefault ( ) ? . RoleId ) . ObjToInt ( ) ;
274286 if ( roleId > 0 )
0 commit comments