11using System ;
22using System . Linq ;
33using System . Threading . Tasks ;
4+ using AutoMapper ;
45using Admin . Core . Model . Admin ;
56using Admin . Core . Common . Output ;
67using Admin . Core . Repository . Admin ;
7- using Admin . Core . Common . Helpers ;
88using Admin . Core . Common . Auth ;
99using Admin . Core . Common . Cache ;
10+ using Admin . Core . Common . Configs ;
11+ using Admin . Core . Common . Helpers ;
1012using Admin . Core . Service . Admin . Auth . Input ;
11- using AutoMapper ;
1213using Admin . Core . Service . Admin . Auth . Output ;
1314
1415namespace Admin . Core . Service . Admin . Auth
@@ -18,6 +19,7 @@ public class AuthService : IAuthService
1819 private readonly IUser _user ;
1920 private readonly ICache _cache ;
2021 private readonly IMapper _mapper ;
22+ private readonly AppConfig _appConfig ;
2123 private readonly VerifyCodeHelper _verifyCodeHelper ;
2224 private readonly IUserRepository _userRepository ;
2325 private readonly IPermissionRepository _permissionRepository ;
@@ -26,6 +28,7 @@ public AuthService(
2628 IUser user ,
2729 ICache cache ,
2830 IMapper mapper ,
31+ AppConfig appConfig ,
2932 VerifyCodeHelper verifyCodeHelper ,
3033 IUserRepository userRepository ,
3134 IPermissionRepository permissionRepository
@@ -34,6 +37,7 @@ IPermissionRepository permissionRepository
3437 _user = user ;
3538 _cache = cache ;
3639 _mapper = mapper ;
40+ _appConfig = appConfig ;
3741 _verifyCodeHelper = verifyCodeHelper ;
3842 _userRepository = userRepository ;
3943 _permissionRepository = permissionRepository ;
@@ -42,24 +46,27 @@ IPermissionRepository permissionRepository
4246 public async Task < IResponseOutput > LoginAsync ( AuthLoginInput input )
4347 {
4448 #region 验证码校验
45- var verifyCodeKey = string . Format ( CacheKey . VerifyCodeKey , input . VerifyCodeKey ) ;
46- var exists = await _cache . ExistsAsync ( verifyCodeKey ) ;
47- if ( exists )
49+ if ( _appConfig . VarifyCode . Enabled )
4850 {
49- var verifyCode = await _cache . GetAsync ( verifyCodeKey ) ;
50- if ( string . IsNullOrEmpty ( verifyCode ) )
51+ var verifyCodeKey = string . Format ( CacheKey . VerifyCodeKey , input . VerifyCodeKey ) ;
52+ var exists = await _cache . ExistsAsync ( verifyCodeKey ) ;
53+ if ( exists )
5154 {
52- return ResponseOutput . NotOk ( "验证码已过期!" , 1 ) ;
55+ var verifyCode = await _cache . GetAsync ( verifyCodeKey ) ;
56+ if ( string . IsNullOrEmpty ( verifyCode ) )
57+ {
58+ return ResponseOutput . NotOk ( "验证码已过期!" , 1 ) ;
59+ }
60+ if ( verifyCode . ToLower ( ) != input . VerifyCode . ToLower ( ) )
61+ {
62+ return ResponseOutput . NotOk ( "验证码输入有误!" , 2 ) ;
63+ }
64+ await _cache . DelAsync ( verifyCodeKey ) ;
5365 }
54- if ( verifyCode . ToLower ( ) != input . VerifyCode . ToLower ( ) )
66+ else
5567 {
56- return ResponseOutput . NotOk ( "验证码输入有误 !" , 2 ) ;
68+ return ResponseOutput . NotOk ( "验证码已过期 !" , 1 ) ;
5769 }
58- await _cache . DelAsync ( verifyCodeKey ) ;
59- }
60- else
61- {
62- return ResponseOutput . NotOk ( "验证码已过期!" , 1 ) ;
6370 }
6471 #endregion
6572
@@ -143,7 +150,17 @@ public async Task<IResponseOutput> GetUserInfoAsync()
143150 a . External
144151 } ) ;
145152
146- return ResponseOutput . Ok ( new { user , menus } ) ;
153+ var permissions = await _permissionRepository . Select
154+ . Where ( a => a . Type == PermissionType . Api )
155+ . Where ( a =>
156+ _permissionRepository . Orm . Select < RolePermissionEntity > ( )
157+ . InnerJoin < UserRoleEntity > ( ( b , c ) => b . RoleId == c . RoleId && c . UserId == _user . Id )
158+ . Where ( b => b . PermissionId == a . Id )
159+ . Any ( )
160+ )
161+ . ToListAsync ( a => a . Code ) ;
162+
163+ return ResponseOutput . Ok ( new { user , menus , permissions } ) ;
147164 }
148165
149166 public async Task < IResponseOutput > GetVerifyCodeAsync ( string lastKey )
@@ -161,8 +178,7 @@ public async Task<IResponseOutput> GetVerifyCodeAsync(string lastKey)
161178 var key = string . Format ( CacheKey . VerifyCodeKey , guid ) ;
162179 await _cache . SetAsync ( key , code , TimeSpan . FromMinutes ( 5 ) ) ;
163180
164- var data = new { key = guid , img } ;
165-
181+ var data = new AuthGetVerifyCodeOutput { Key = guid , Img = img } ;
166182 return ResponseOutput . Ok ( data ) ;
167183 }
168184
0 commit comments