11using System ;
22using System . Linq ;
33using System . Threading . Tasks ;
4- using System . Security . Claims ;
54using Admin . Core . Model . Admin ;
65using Admin . Core . Model . Output ;
76using Admin . Core . Repository . Admin ;
@@ -19,24 +18,24 @@ public class AuthService : IAuthService
1918 private readonly IUser _user ;
2019 private readonly ICache _cache ;
2120 private readonly IMapper _mapper ;
22- private readonly IUserToken _userToken ;
2321 private readonly IUserRepository _userRepository ;
22+ private readonly IPermissionRepository _permissionRepository ;
2423 private readonly IRolePermissionRepository _rolePermissionRepository ;
2524
2625 public AuthService (
2726 IUser user ,
2827 ICache cache ,
2928 IMapper mapper ,
30- IUserToken userToken ,
3129 IUserRepository userRepository ,
30+ IPermissionRepository permissionRepository ,
3231 IRolePermissionRepository rolePermissionRepository
3332 )
3433 {
3534 _user = user ;
3635 _cache = cache ;
3736 _mapper = mapper ;
38- _userToken = userToken ;
3937 _userRepository = userRepository ;
38+ _permissionRepository = permissionRepository ;
4039 _rolePermissionRepository = rolePermissionRepository ;
4140 }
4241
@@ -50,11 +49,11 @@ public async Task<IResponseOutput> LoginAsync(AuthLoginInput input)
5049 var verifyCode = await _cache . GetAsync ( verifyCodeKey ) ;
5150 if ( string . IsNullOrEmpty ( verifyCode ) )
5251 {
53- return ResponseOutput . NotOk ( "验证码已过期!" , 1 ) ;
52+ return ResponseOutput . NotOk ( "验证码已过期!" , 1 ) ;
5453 }
5554 if ( verifyCode . ToLower ( ) != input . VerifyCode . ToLower ( ) )
5655 {
57- return ResponseOutput . NotOk ( "验证码输入有误!" , 2 ) ;
56+ return ResponseOutput . NotOk ( "验证码输入有误!" , 2 ) ;
5857 }
5958 await _cache . DelAsync ( verifyCodeKey ) ;
6059 }
@@ -80,22 +79,22 @@ public async Task<IResponseOutput> LoginAsync(AuthLoginInput input)
8079 var secretKey = await _cache . GetAsync ( passwordEncryptKey ) ;
8180 if ( passwordEncryptKey . IsNull ( ) )
8281 {
83- return ResponseOutput . NotOk ( "解密失败!" , 1 ) ;
82+ return ResponseOutput . NotOk ( "解密失败!" , 1 ) ;
8483 }
8584 input . Password = DesEncrypt . Decrypt ( input . Password , secretKey ) ;
8685 await _cache . DelAsync ( passwordEncryptKey ) ;
8786 }
8887 else
8988 {
90- return ResponseOutput . NotOk ( "解密失败!" , 1 ) ;
89+ return ResponseOutput . NotOk ( "解密失败!" , 1 ) ;
9190 }
9291 }
9392 #endregion
9493
9594 var password = MD5Encrypt . Encrypt32 ( input . Password ) ;
9695 if ( user . Password != password )
9796 {
98- return ResponseOutput . NotOk ( "密码输入有误!" , 4 ) ;
97+ return ResponseOutput . NotOk ( "密码输入有误!" , 4 ) ;
9998 }
10099
101100 var authLoginOutput = _mapper . Map < AuthLoginOutput > ( user ) ;
@@ -111,34 +110,36 @@ public async Task<IResponseOutput> GetUserInfoAsync()
111110 }
112111
113112 var user = await _userRepository . Select . WhereDynamic ( _user . Id )
114- . ToOneAsync ( m=> new {
113+ . ToOneAsync ( m => new {
115114 m . NickName ,
116115 m . Name ,
117116 m . Avatar
118117 } ) ;
119118
120119 //获取菜单
121- var menus = await _rolePermissionRepository . Select
122- . InnerJoin < UserRoleEntity > ( ( a , b ) => a . RoleId == b . RoleId && b . UserId == _user . Id )
123- . Include ( a => a . Permission . View )
124- . Where ( a => new [ ] { PermissionType . Group , PermissionType . Menu } . Contains ( a . Permission . Type ) )
125- //.Distinct()
126- . OrderBy ( a => a . Permission . ParentId )
127- . OrderBy ( a => a . Permission . Sort )
120+ var menus = await _permissionRepository . Select
121+ . Where ( a => new [ ] { PermissionType . Group , PermissionType . Menu } . Contains ( a . Type ) )
122+ . Where ( a =>
123+ _rolePermissionRepository . Select
124+ . InnerJoin < UserRoleEntity > ( ( b , c ) => b . RoleId == c . RoleId && b . PermissionId == a . Id && c . UserId == _user . Id )
125+ . Any ( )
126+ )
127+ . OrderBy ( a => a . ParentId )
128+ . OrderBy ( a => a . Sort )
128129 . ToListAsync ( a => new
129130 {
130- a . Permission . Id ,
131- a . Permission . ParentId ,
132- a . Permission . Path ,
133- ViewPath = a . Permission . View . Path ,
134- a . Permission . Label ,
135-
136- a . Permission . Icon ,
137- a . Permission . Opened ,
138- a . Permission . Closable ,
139- a . Permission . Hidden ,
140- a . Permission . NewWindow ,
141- a . Permission . External
131+ a . Id ,
132+ a . ParentId ,
133+ a . Path ,
134+ ViewPath = a . View . Path ,
135+ a . Label ,
136+
137+ a . Icon ,
138+ a . Opened ,
139+ a . Closable ,
140+ a . Hidden ,
141+ a . NewWindow ,
142+ a . External
142143 } ) ;
143144
144145 return ResponseOutput . Ok ( new { user , menus } ) ;
0 commit comments