|
@@ -31,304 +31,303 @@ using System.Text;
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
using Microsoft.IdentityModel.JsonWebTokens;
|
|
|
|
|
|
-namespace ZhonTai.Admin.Services.Auth
|
|
|
+namespace ZhonTai.Admin.Services.Auth;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+[DynamicApi(Area = AdminConsts.AreaName)]
|
|
|
+public class AuthService : BaseService, IAuthService, IDynamicApi
|
|
|
{
|
|
|
+ private readonly AppConfig _appConfig;
|
|
|
+ private readonly JwtConfig _jwtConfig;
|
|
|
+ private readonly IPermissionRepository _permissionRepository;
|
|
|
+ private readonly IUserRepository _userRepository;
|
|
|
+ private readonly ITenantRepository _tenantRepository;
|
|
|
+ private readonly ICaptchaTool _captchaTool;
|
|
|
+
|
|
|
+ public AuthService(
|
|
|
+ AppConfig appConfig,
|
|
|
+ JwtConfig jwtConfig,
|
|
|
+ IUserRepository userRepository,
|
|
|
+ IPermissionRepository permissionRepository,
|
|
|
+ ITenantRepository tenantRepository,
|
|
|
+ ICaptchaTool captchaTool
|
|
|
+ )
|
|
|
+ {
|
|
|
+ _appConfig = appConfig;
|
|
|
+ _jwtConfig = jwtConfig;
|
|
|
+ _userRepository = userRepository;
|
|
|
+ _permissionRepository = permissionRepository;
|
|
|
+ _tenantRepository = tenantRepository;
|
|
|
+ _captchaTool = captchaTool;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- [DynamicApi(Area = "admin")]
|
|
|
- public class AuthService : BaseService, IAuthService, IDynamicApi
|
|
|
+
|
|
|
+
|
|
|
+ private string GetToken(AuthLoginOutput user)
|
|
|
{
|
|
|
- private readonly AppConfig _appConfig;
|
|
|
- private readonly JwtConfig _jwtConfig;
|
|
|
- private readonly IPermissionRepository _permissionRepository;
|
|
|
- private readonly IUserRepository _userRepository;
|
|
|
- private readonly ITenantRepository _tenantRepository;
|
|
|
- private readonly ICaptchaTool _captchaTool;
|
|
|
-
|
|
|
- public AuthService(
|
|
|
- AppConfig appConfig,
|
|
|
- JwtConfig jwtConfig,
|
|
|
- IUserRepository userRepository,
|
|
|
- IPermissionRepository permissionRepository,
|
|
|
- ITenantRepository tenantRepository,
|
|
|
- ICaptchaTool captchaTool
|
|
|
- )
|
|
|
+ if (user == null)
|
|
|
{
|
|
|
- _appConfig = appConfig;
|
|
|
- _jwtConfig = jwtConfig;
|
|
|
- _userRepository = userRepository;
|
|
|
- _permissionRepository = permissionRepository;
|
|
|
- _tenantRepository = tenantRepository;
|
|
|
- _captchaTool = captchaTool;
|
|
|
+ return string.Empty;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private string GetToken(AuthLoginOutput user)
|
|
|
+ var token = LazyGetRequiredService<IUserToken>().Create(new[]
|
|
|
{
|
|
|
- if (user == null)
|
|
|
- {
|
|
|
- return string.Empty;
|
|
|
- }
|
|
|
+ new Claim(ClaimAttributes.UserId, user.Id.ToString()),
|
|
|
+ new Claim(ClaimAttributes.UserName, user.UserName),
|
|
|
+ new Claim(ClaimAttributes.UserNickName, user.NickName),
|
|
|
+ new Claim(ClaimAttributes.TenantId, user.TenantId.ToString()),
|
|
|
+ new Claim(ClaimAttributes.TenantType, user.TenantType.ToString()),
|
|
|
+ new Claim(ClaimAttributes.DataIsolationType, user.DataIsolationType.ToString())
|
|
|
+ });
|
|
|
+
|
|
|
+ return token;
|
|
|
+ }
|
|
|
|
|
|
- var token = LazyGetRequiredService<IUserToken>().Create(new[]
|
|
|
- {
|
|
|
- new Claim(ClaimAttributes.UserId, user.Id.ToString()),
|
|
|
- new Claim(ClaimAttributes.UserName, user.UserName),
|
|
|
- new Claim(ClaimAttributes.UserNickName, user.NickName),
|
|
|
- new Claim(ClaimAttributes.TenantId, user.TenantId.ToString()),
|
|
|
- new Claim(ClaimAttributes.TenantType, user.TenantType.ToString()),
|
|
|
- new Claim(ClaimAttributes.DataIsolationType, user.DataIsolationType.ToString())
|
|
|
- });
|
|
|
-
|
|
|
- return token;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ [NoOprationLog]
|
|
|
+ public async Task<IResultOutput> GetPasswordEncryptKeyAsync()
|
|
|
+ {
|
|
|
+
|
|
|
+ var guid = Guid.NewGuid().ToString("N");
|
|
|
+ var key = string.Format(CacheKeys.PassWordEncryptKey, guid);
|
|
|
+ var encyptKey = StringHelper.GenerateRandom(8);
|
|
|
+ await Cache.SetAsync(key, encyptKey, TimeSpan.FromMinutes(5));
|
|
|
+ var data = new { key = guid, encyptKey };
|
|
|
+
|
|
|
+ return ResultOutput.Ok(data);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [HttpGet]
|
|
|
- [AllowAnonymous]
|
|
|
- [NoOprationLog]
|
|
|
- public async Task<IResultOutput> GetPasswordEncryptKeyAsync()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [Login]
|
|
|
+ public async Task<IResultOutput> GetUserInfoAsync()
|
|
|
+ {
|
|
|
+ if (!(User?.Id > 0))
|
|
|
{
|
|
|
-
|
|
|
- var guid = Guid.NewGuid().ToString("N");
|
|
|
- var key = string.Format(CacheKeys.PassWordEncryptKey, guid);
|
|
|
- var encyptKey = StringHelper.GenerateRandom(8);
|
|
|
- await Cache.SetAsync(key, encyptKey, TimeSpan.FromMinutes(5));
|
|
|
- var data = new { key = guid, encyptKey };
|
|
|
-
|
|
|
- return ResultOutput.Ok(data);
|
|
|
+ return ResultOutput.NotOk("未登录!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [Login]
|
|
|
- public async Task<IResultOutput> GetUserInfoAsync()
|
|
|
+ var authUserInfoOutput = new AuthUserInfoOutput
|
|
|
{
|
|
|
- if (!(User?.Id > 0))
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("未登录!");
|
|
|
- }
|
|
|
-
|
|
|
- var authUserInfoOutput = new AuthUserInfoOutput
|
|
|
- {
|
|
|
-
|
|
|
- User = await _userRepository.GetAsync<AuthUserProfileDto>(User.Id),
|
|
|
-
|
|
|
-
|
|
|
- Menus = await _permissionRepository.Select
|
|
|
- .Where(a => new[] { PermissionTypeEnum.Group, PermissionTypeEnum.Menu }.Contains(a.Type))
|
|
|
- .Where(a =>
|
|
|
- _permissionRepository.Orm.Select<RolePermissionEntity>()
|
|
|
- .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
|
|
|
- .Where(b => b.PermissionId == a.Id)
|
|
|
- .Any()
|
|
|
- )
|
|
|
- .OrderBy(a => a.ParentId)
|
|
|
- .OrderBy(a => a.Sort)
|
|
|
- .ToListAsync(a => new AuthUserMenuDto { ViewPath = a.View.Path }),
|
|
|
-
|
|
|
-
|
|
|
- Permissions = await _permissionRepository.Select
|
|
|
- .Where(a => a.Type == PermissionTypeEnum.Dot)
|
|
|
- .Where(a =>
|
|
|
- _permissionRepository.Orm.Select<RolePermissionEntity>()
|
|
|
- .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
|
|
|
- .Where(b => b.PermissionId == a.Id)
|
|
|
- .Any()
|
|
|
- )
|
|
|
- .ToListAsync(a => a.Code)
|
|
|
- };
|
|
|
-
|
|
|
- return ResultOutput.Ok(authUserInfoOutput);
|
|
|
- }
|
|
|
+
|
|
|
+ User = await _userRepository.GetAsync<AuthUserProfileDto>(User.Id),
|
|
|
+
|
|
|
+
|
|
|
+ Menus = await _permissionRepository.Select
|
|
|
+ .Where(a => new[] { PermissionTypeEnum.Group, PermissionTypeEnum.Menu }.Contains(a.Type))
|
|
|
+ .Where(a =>
|
|
|
+ _permissionRepository.Orm.Select<RolePermissionEntity>()
|
|
|
+ .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
|
|
|
+ .Where(b => b.PermissionId == a.Id)
|
|
|
+ .Any()
|
|
|
+ )
|
|
|
+ .OrderBy(a => a.ParentId)
|
|
|
+ .OrderBy(a => a.Sort)
|
|
|
+ .ToListAsync(a => new AuthUserMenuDto { ViewPath = a.View.Path }),
|
|
|
+
|
|
|
+
|
|
|
+ Permissions = await _permissionRepository.Select
|
|
|
+ .Where(a => a.Type == PermissionTypeEnum.Dot)
|
|
|
+ .Where(a =>
|
|
|
+ _permissionRepository.Orm.Select<RolePermissionEntity>()
|
|
|
+ .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
|
|
|
+ .Where(b => b.PermissionId == a.Id)
|
|
|
+ .Any()
|
|
|
+ )
|
|
|
+ .ToListAsync(a => a.Code)
|
|
|
+ };
|
|
|
+
|
|
|
+ return ResultOutput.Ok(authUserInfoOutput);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [HttpPost]
|
|
|
- [AllowAnonymous]
|
|
|
- [NoOprationLog]
|
|
|
- public async Task<IResultOutput> LoginAsync(AuthLoginInput input)
|
|
|
- {
|
|
|
- var sw = new Stopwatch();
|
|
|
- sw.Start();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpPost]
|
|
|
+ [AllowAnonymous]
|
|
|
+ [NoOprationLog]
|
|
|
+ public async Task<IResultOutput> LoginAsync(AuthLoginInput input)
|
|
|
+ {
|
|
|
+ var sw = new Stopwatch();
|
|
|
+ sw.Start();
|
|
|
|
|
|
- #region 验证码校验
|
|
|
+ #region 验证码校验
|
|
|
|
|
|
- if (_appConfig.VarifyCode.Enable)
|
|
|
+ if (_appConfig.VarifyCode.Enable)
|
|
|
+ {
|
|
|
+ input.Captcha.DeleteCache = true;
|
|
|
+ input.Captcha.CaptchaKey = CacheKeys.CaptchaKey;
|
|
|
+ var isOk = await _captchaTool.CheckAsync(input.Captcha);
|
|
|
+ if (!isOk)
|
|
|
{
|
|
|
- input.Captcha.DeleteCache = true;
|
|
|
- input.Captcha.CaptchaKey = CacheKeys.CaptchaKey;
|
|
|
- var isOk = await _captchaTool.CheckAsync(input.Captcha);
|
|
|
- if (!isOk)
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("安全验证不通过,请重新登录!");
|
|
|
- }
|
|
|
+ return ResultOutput.NotOk("安全验证不通过,请重新登录!");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- #endregion 验证码校验
|
|
|
+ #endregion 验证码校验
|
|
|
|
|
|
- UserEntity user = null;
|
|
|
+ UserEntity user = null;
|
|
|
|
|
|
- user = await _userRepository.Select.DisableGlobalFilter("Tenant").Where(a => a.UserName == input.UserName).ToOneAsync();
|
|
|
+ user = await _userRepository.Select.DisableGlobalFilter("Tenant").Where(a => a.UserName == input.UserName).ToOneAsync();
|
|
|
|
|
|
- if (!(user?.Id > 0))
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("账号输入有误!", 3);
|
|
|
- }
|
|
|
+ if (!(user?.Id > 0))
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk("账号输入有误!", 3);
|
|
|
+ }
|
|
|
|
|
|
- #region 解密
|
|
|
+ #region 解密
|
|
|
|
|
|
- if (input.PasswordKey.NotNull())
|
|
|
+ if (input.PasswordKey.NotNull())
|
|
|
+ {
|
|
|
+ var passwordEncryptKey = string.Format(CacheKeys.PassWordEncryptKey, input.PasswordKey);
|
|
|
+ var existsPasswordKey = await Cache.ExistsAsync(passwordEncryptKey);
|
|
|
+ if (existsPasswordKey)
|
|
|
{
|
|
|
- var passwordEncryptKey = string.Format(CacheKeys.PassWordEncryptKey, input.PasswordKey);
|
|
|
- var existsPasswordKey = await Cache.ExistsAsync(passwordEncryptKey);
|
|
|
- if (existsPasswordKey)
|
|
|
- {
|
|
|
- var secretKey = await Cache.GetAsync(passwordEncryptKey);
|
|
|
- if (secretKey.IsNull())
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("解密失败!", 1);
|
|
|
- }
|
|
|
- input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
|
- await Cache.DelAsync(passwordEncryptKey);
|
|
|
- }
|
|
|
- else
|
|
|
+ var secretKey = await Cache.GetAsync(passwordEncryptKey);
|
|
|
+ if (secretKey.IsNull())
|
|
|
{
|
|
|
return ResultOutput.NotOk("解密失败!", 1);
|
|
|
}
|
|
|
+ input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
|
+ await Cache.DelAsync(passwordEncryptKey);
|
|
|
}
|
|
|
-
|
|
|
- #endregion 解密
|
|
|
-
|
|
|
- var password = MD5Encrypt.Encrypt32(input.Password);
|
|
|
- if (user.Password != password)
|
|
|
+ else
|
|
|
{
|
|
|
- return ResultOutput.NotOk("密码输入有误!", 4);
|
|
|
+ return ResultOutput.NotOk("解密失败!", 1);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- var authLoginOutput = Mapper.Map<AuthLoginOutput>(user);
|
|
|
+ #endregion 解密
|
|
|
|
|
|
- if (_appConfig.Tenant)
|
|
|
- {
|
|
|
- var tenant = await _tenantRepository.Select.DisableGlobalFilter("Tenant").WhereDynamic(user.TenantId).ToOneAsync(a => new { a.TenantType, a.DataIsolationType });
|
|
|
- authLoginOutput.TenantType = tenant.TenantType;
|
|
|
- authLoginOutput.DataIsolationType = tenant.DataIsolationType;
|
|
|
- }
|
|
|
+ var password = MD5Encrypt.Encrypt32(input.Password);
|
|
|
+ if (user.Password != password)
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk("密码输入有误!", 4);
|
|
|
+ }
|
|
|
|
|
|
- string token = GetToken(authLoginOutput);
|
|
|
+ var authLoginOutput = Mapper.Map<AuthLoginOutput>(user);
|
|
|
|
|
|
- sw.Stop();
|
|
|
+ if (_appConfig.Tenant)
|
|
|
+ {
|
|
|
+ var tenant = await _tenantRepository.Select.DisableGlobalFilter("Tenant").WhereDynamic(user.TenantId).ToOneAsync(a => new { a.TenantType, a.DataIsolationType });
|
|
|
+ authLoginOutput.TenantType = tenant.TenantType;
|
|
|
+ authLoginOutput.DataIsolationType = tenant.DataIsolationType;
|
|
|
+ }
|
|
|
|
|
|
- #region 添加登录日志
|
|
|
+ string token = GetToken(authLoginOutput);
|
|
|
|
|
|
- var loginLogAddInput = new LoginLogAddInput
|
|
|
- {
|
|
|
- CreatedUserName = input.UserName,
|
|
|
- ElapsedMilliseconds = sw.ElapsedMilliseconds,
|
|
|
- Status = true,
|
|
|
- CreatedUserId = authLoginOutput.Id,
|
|
|
- NickName = authLoginOutput.NickName,
|
|
|
- TenantId = authLoginOutput.TenantId
|
|
|
- };
|
|
|
+ sw.Stop();
|
|
|
|
|
|
- await LazyGetRequiredService<ILoginLogService>().AddAsync(loginLogAddInput);
|
|
|
+ #region 添加登录日志
|
|
|
|
|
|
- #endregion 添加登录日志
|
|
|
+ var loginLogAddInput = new LoginLogAddInput
|
|
|
+ {
|
|
|
+ CreatedUserName = input.UserName,
|
|
|
+ ElapsedMilliseconds = sw.ElapsedMilliseconds,
|
|
|
+ Status = true,
|
|
|
+ CreatedUserId = authLoginOutput.Id,
|
|
|
+ NickName = authLoginOutput.NickName,
|
|
|
+ TenantId = authLoginOutput.TenantId
|
|
|
+ };
|
|
|
|
|
|
- return ResultOutput.Ok(new { token });
|
|
|
- }
|
|
|
+ await LazyGetRequiredService<ILoginLogService>().AddAsync(loginLogAddInput);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [HttpGet]
|
|
|
- [AllowAnonymous]
|
|
|
- public async Task<IResultOutput> Refresh([BindRequired] string token)
|
|
|
- {
|
|
|
- var jwtSecurityToken = LazyGetRequiredService<IUserToken>().Decode(token);
|
|
|
- var userClaims = jwtSecurityToken?.Claims?.ToArray();
|
|
|
- if (userClaims == null || userClaims.Length == 0)
|
|
|
- {
|
|
|
- return ResultOutput.NotOk();
|
|
|
- }
|
|
|
+ #endregion 添加登录日志
|
|
|
|
|
|
- var refreshExpires = userClaims.FirstOrDefault(a => a.Type == ClaimAttributes.RefreshExpires)?.Value;
|
|
|
- if (refreshExpires.IsNull())
|
|
|
- {
|
|
|
- return ResultOutput.NotOk();
|
|
|
- }
|
|
|
+ return ResultOutput.Ok(new { token });
|
|
|
+ }
|
|
|
|
|
|
- if (refreshExpires.ToLong() <= DateTime.Now.ToTimestamp())
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("登录信息已过期");
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public async Task<IResultOutput> Refresh([BindRequired] string token)
|
|
|
+ {
|
|
|
+ var jwtSecurityToken = LazyGetRequiredService<IUserToken>().Decode(token);
|
|
|
+ var userClaims = jwtSecurityToken?.Claims?.ToArray();
|
|
|
+ if (userClaims == null || userClaims.Length == 0)
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk();
|
|
|
+ }
|
|
|
|
|
|
- var userId = userClaims.FirstOrDefault(a => a.Type == ClaimAttributes.UserId)?.Value;
|
|
|
- if (userId.IsNull())
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("登录信息已失效");
|
|
|
- }
|
|
|
+ var refreshExpires = userClaims.FirstOrDefault(a => a.Type == ClaimAttributes.RefreshExpires)?.Value;
|
|
|
+ if (refreshExpires.IsNull())
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk();
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- var securityKey = _jwtConfig.SecurityKey;
|
|
|
- var signingCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(securityKey)), SecurityAlgorithms.HmacSha256);
|
|
|
- var input = jwtSecurityToken.RawHeader + "." + jwtSecurityToken.RawPayload;
|
|
|
- if (jwtSecurityToken.RawSignature != JwtTokenUtilities.CreateEncodedSignature(input, signingCredentials))
|
|
|
- {
|
|
|
- return ResultOutput.NotOk("验签失败");
|
|
|
- }
|
|
|
+ if (refreshExpires.ToLong() <= DateTime.Now.ToTimestamp())
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk("登录信息已过期");
|
|
|
+ }
|
|
|
|
|
|
- var output = await LazyGetRequiredService<IUserService>().GetLoginUserAsync(userId.ToLong());
|
|
|
- string newToken = GetToken(output?.Data);
|
|
|
- return ResultOutput.Ok(new { token = newToken });
|
|
|
+ var userId = userClaims.FirstOrDefault(a => a.Type == ClaimAttributes.UserId)?.Value;
|
|
|
+ if (userId.IsNull())
|
|
|
+ {
|
|
|
+ return ResultOutput.NotOk("登录信息已失效");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [HttpGet]
|
|
|
- [AllowAnonymous]
|
|
|
- [NoOprationLog]
|
|
|
- [EnableCors(AdminConsts.AllowAnyPolicyName)]
|
|
|
- public async Task<IResultOutput> GetCaptcha()
|
|
|
+
|
|
|
+ var securityKey = _jwtConfig.SecurityKey;
|
|
|
+ var signingCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(securityKey)), SecurityAlgorithms.HmacSha256);
|
|
|
+ var input = jwtSecurityToken.RawHeader + "." + jwtSecurityToken.RawPayload;
|
|
|
+ if (jwtSecurityToken.RawSignature != JwtTokenUtilities.CreateEncodedSignature(input, signingCredentials))
|
|
|
{
|
|
|
- using (MiniProfiler.Current.Step("获取滑块验证"))
|
|
|
- {
|
|
|
- var data = await _captchaTool.GetAsync(CacheKeys.CaptchaKey);
|
|
|
- return ResultOutput.Ok(data);
|
|
|
- }
|
|
|
+ return ResultOutput.NotOk("验签失败");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [HttpGet]
|
|
|
- [AllowAnonymous]
|
|
|
- [NoOprationLog]
|
|
|
- [EnableCors(AdminConsts.AllowAnyPolicyName)]
|
|
|
- public async Task<IResultOutput> CheckCaptcha([FromQuery] CaptchaInput input)
|
|
|
+ var output = await LazyGetRequiredService<IUserService>().GetLoginUserAsync(userId.ToLong());
|
|
|
+ string newToken = GetToken(output?.Data);
|
|
|
+ return ResultOutput.Ok(new { token = newToken });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ [NoOprationLog]
|
|
|
+ [EnableCors(AdminConsts.AllowAnyPolicyName)]
|
|
|
+ public async Task<IResultOutput> GetCaptcha()
|
|
|
+ {
|
|
|
+ using (MiniProfiler.Current.Step("获取滑块验证"))
|
|
|
{
|
|
|
- input.CaptchaKey = CacheKeys.CaptchaKey;
|
|
|
- var result = await _captchaTool.CheckAsync(input);
|
|
|
- return ResultOutput.Result(result);
|
|
|
+ var data = await _captchaTool.GetAsync(CacheKeys.CaptchaKey);
|
|
|
+ return ResultOutput.Ok(data);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ [NoOprationLog]
|
|
|
+ [EnableCors(AdminConsts.AllowAnyPolicyName)]
|
|
|
+ public async Task<IResultOutput> CheckCaptcha([FromQuery] CaptchaInput input)
|
|
|
+ {
|
|
|
+ input.CaptchaKey = CacheKeys.CaptchaKey;
|
|
|
+ var result = await _captchaTool.CheckAsync(input);
|
|
|
+ return ResultOutput.Result(result);
|
|
|
+ }
|
|
|
}
|