|
@@ -15,14 +15,12 @@ namespace Admin.Core.Service.Admin.Auth
|
|
public class AuthService : BaseService, IAuthService
|
|
public class AuthService : BaseService, IAuthService
|
|
{
|
|
{
|
|
private readonly AppConfig _appConfig;
|
|
private readonly AppConfig _appConfig;
|
|
- private readonly ICache _cache;
|
|
|
|
private readonly IPermissionRepository _permissionRepository;
|
|
private readonly IPermissionRepository _permissionRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly VerifyCodeHelper _verifyCodeHelper;
|
|
private readonly VerifyCodeHelper _verifyCodeHelper;
|
|
private readonly ITenantRepository _tenantRepository;
|
|
private readonly ITenantRepository _tenantRepository;
|
|
|
|
|
|
public AuthService(
|
|
public AuthService(
|
|
- ICache cache,
|
|
|
|
AppConfig appConfig,
|
|
AppConfig appConfig,
|
|
VerifyCodeHelper verifyCodeHelper,
|
|
VerifyCodeHelper verifyCodeHelper,
|
|
IUserRepository userRepository,
|
|
IUserRepository userRepository,
|
|
@@ -30,7 +28,6 @@ namespace Admin.Core.Service.Admin.Auth
|
|
ITenantRepository tenantRepository
|
|
ITenantRepository tenantRepository
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- _cache = cache;
|
|
|
|
_appConfig = appConfig;
|
|
_appConfig = appConfig;
|
|
_verifyCodeHelper = verifyCodeHelper;
|
|
_verifyCodeHelper = verifyCodeHelper;
|
|
_userRepository = userRepository;
|
|
_userRepository = userRepository;
|
|
@@ -44,7 +41,7 @@ namespace Admin.Core.Service.Admin.Auth
|
|
var guid = Guid.NewGuid().ToString("N");
|
|
var guid = Guid.NewGuid().ToString("N");
|
|
var key = string.Format(CacheKey.PassWordEncryptKey, guid);
|
|
var key = string.Format(CacheKey.PassWordEncryptKey, guid);
|
|
var encyptKey = StringHelper.GenerateRandom(8);
|
|
var encyptKey = StringHelper.GenerateRandom(8);
|
|
- await _cache.SetAsync(key, encyptKey, TimeSpan.FromMinutes(5));
|
|
|
|
|
|
+ await Cache.SetAsync(key, encyptKey, TimeSpan.FromMinutes(5));
|
|
var data = new { key = guid, encyptKey };
|
|
var data = new { key = guid, encyptKey };
|
|
|
|
|
|
return ResponseOutput.Ok(data);
|
|
return ResponseOutput.Ok(data);
|
|
@@ -58,7 +55,7 @@ namespace Admin.Core.Service.Admin.Auth
|
|
}
|
|
}
|
|
|
|
|
|
var key = string.Format(CacheKey.UserInfo, User.Id);
|
|
var key = string.Format(CacheKey.UserInfo, User.Id);
|
|
- var output = await _cache.GetOrSetAsync(key, async () =>
|
|
|
|
|
|
+ var output = await Cache.GetOrSetAsync(key, async () =>
|
|
{
|
|
{
|
|
var authUserInfoOutput = new AuthUserInfoOutput { };
|
|
var authUserInfoOutput = new AuthUserInfoOutput { };
|
|
//用户信息
|
|
//用户信息
|
|
@@ -101,13 +98,13 @@ namespace Admin.Core.Service.Admin.Auth
|
|
//删除上次缓存的验证码
|
|
//删除上次缓存的验证码
|
|
if (lastKey.NotNull())
|
|
if (lastKey.NotNull())
|
|
{
|
|
{
|
|
- await _cache.DelAsync(lastKey);
|
|
|
|
|
|
+ await Cache.DelAsync(lastKey);
|
|
}
|
|
}
|
|
|
|
|
|
//写入Redis
|
|
//写入Redis
|
|
var guid = Guid.NewGuid().ToString("N");
|
|
var guid = Guid.NewGuid().ToString("N");
|
|
var key = string.Format(CacheKey.VerifyCodeKey, guid);
|
|
var key = string.Format(CacheKey.VerifyCodeKey, guid);
|
|
- await _cache.SetAsync(key, code, TimeSpan.FromMinutes(5));
|
|
|
|
|
|
+ await Cache.SetAsync(key, code, TimeSpan.FromMinutes(5));
|
|
|
|
|
|
var data = new AuthGetVerifyCodeOutput { Key = guid, Img = img };
|
|
var data = new AuthGetVerifyCodeOutput { Key = guid, Img = img };
|
|
return ResponseOutput.Ok(data);
|
|
return ResponseOutput.Ok(data);
|
|
@@ -120,10 +117,10 @@ namespace Admin.Core.Service.Admin.Auth
|
|
if (_appConfig.VarifyCode.Enable)
|
|
if (_appConfig.VarifyCode.Enable)
|
|
{
|
|
{
|
|
var verifyCodeKey = string.Format(CacheKey.VerifyCodeKey, input.VerifyCodeKey);
|
|
var verifyCodeKey = string.Format(CacheKey.VerifyCodeKey, input.VerifyCodeKey);
|
|
- var exists = await _cache.ExistsAsync(verifyCodeKey);
|
|
|
|
|
|
+ var exists = await Cache.ExistsAsync(verifyCodeKey);
|
|
if (exists)
|
|
if (exists)
|
|
{
|
|
{
|
|
- var verifyCode = await _cache.GetAsync(verifyCodeKey);
|
|
|
|
|
|
+ var verifyCode = await Cache.GetAsync(verifyCodeKey);
|
|
if (string.IsNullOrEmpty(verifyCode))
|
|
if (string.IsNullOrEmpty(verifyCode))
|
|
{
|
|
{
|
|
return ResponseOutput.NotOk("验证码已过期!", 1);
|
|
return ResponseOutput.NotOk("验证码已过期!", 1);
|
|
@@ -132,7 +129,7 @@ namespace Admin.Core.Service.Admin.Auth
|
|
{
|
|
{
|
|
return ResponseOutput.NotOk("验证码输入有误!", 2);
|
|
return ResponseOutput.NotOk("验证码输入有误!", 2);
|
|
}
|
|
}
|
|
- await _cache.DelAsync(verifyCodeKey);
|
|
|
|
|
|
+ await Cache.DelAsync(verifyCodeKey);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -157,16 +154,16 @@ namespace Admin.Core.Service.Admin.Auth
|
|
if (input.PasswordKey.NotNull())
|
|
if (input.PasswordKey.NotNull())
|
|
{
|
|
{
|
|
var passwordEncryptKey = string.Format(CacheKey.PassWordEncryptKey, input.PasswordKey);
|
|
var passwordEncryptKey = string.Format(CacheKey.PassWordEncryptKey, input.PasswordKey);
|
|
- var existsPasswordKey = await _cache.ExistsAsync(passwordEncryptKey);
|
|
|
|
|
|
+ var existsPasswordKey = await Cache.ExistsAsync(passwordEncryptKey);
|
|
if (existsPasswordKey)
|
|
if (existsPasswordKey)
|
|
{
|
|
{
|
|
- var secretKey = await _cache.GetAsync(passwordEncryptKey);
|
|
|
|
|
|
+ var secretKey = await Cache.GetAsync(passwordEncryptKey);
|
|
if (secretKey.IsNull())
|
|
if (secretKey.IsNull())
|
|
{
|
|
{
|
|
return ResponseOutput.NotOk("解密失败!", 1);
|
|
return ResponseOutput.NotOk("解密失败!", 1);
|
|
}
|
|
}
|
|
input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
- await _cache.DelAsync(passwordEncryptKey);
|
|
|
|
|
|
+ await Cache.DelAsync(passwordEncryptKey);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -192,7 +189,7 @@ namespace Admin.Core.Service.Admin.Auth
|
|
}
|
|
}
|
|
|
|
|
|
//登录清空用户缓存
|
|
//登录清空用户缓存
|
|
- await _cache.DelAsync(string.Format(CacheKey.UserInfo, user.Id));
|
|
|
|
|
|
+ await Cache.DelAsync(string.Format(CacheKey.UserInfo, user.Id));
|
|
|
|
|
|
return ResponseOutput.Ok(authLoginOutput);
|
|
return ResponseOutput.Ok(authLoginOutput);
|
|
}
|
|
}
|