😎调整swagger和大屏登录时默认租户验证码逻辑

This commit is contained in:
zuohuaijun 2025-02-28 11:27:47 +08:00
parent 8a5fa59d26
commit 39c7c03d06
3 changed files with 32 additions and 9 deletions

View File

@ -20,9 +20,9 @@
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" Aliases="BouncyCastleV2" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.17.1" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.16" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.16" />
<PackageReference Include="Furion.Pure" Version="4.9.7.16" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.17" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.17" />
<PackageReference Include="Furion.Pure" Version="4.9.7.17" />
<PackageReference Include="Hardware.Info" Version="101.0.1" />
<PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
@ -48,7 +48,7 @@
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1188" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1189" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>

View File

@ -58,7 +58,7 @@ public class SysAuthService : IDynamicApiController, ITransient
if (passwordMaxErrorTimes < 1) passwordMaxErrorTimes = 5;
if (passwordErrorTimes > passwordMaxErrorTimes) throw Oops.Oh(ErrorCodeEnum.D1027);
// 判断是否开启验证码并校验
// 判断是否开启验证码并校验
var tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.WhereIF(input.TenantId > 0, u => u.Id == input.TenantId).FirstOrDefault();
if (tenant.Captcha == true && !_captcha.Validate(input.CodeId.ToString(), input.Code))
throw Oops.Oh(ErrorCodeEnum.D0008);
@ -387,6 +387,12 @@ public class SysAuthService : IDynamicApiController, ITransient
{
try
{
// 关闭默认租户验证码验证
var tenantList = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant);
var tenant = tenantList.FirstOrDefault(u => u.Id == SqlSugarConst.DefaultTenantId);
tenant.Captcha = false;
_sysCacheService.Set(CacheConst.KeyTenant, tenantList);
await Login(new LoginInput
{
Account = auth.UserName,
@ -394,6 +400,10 @@ public class SysAuthService : IDynamicApiController, ITransient
TenantId = SqlSugarConst.DefaultTenantId
});
// 启用默认租户验证码验证
tenant.Captcha = true;
_sysCacheService.Set(CacheConst.KeyTenant, tenantList);
return 200;
}
catch (Exception)

View File

@ -13,14 +13,17 @@ namespace Admin.NET.Plugin.GoView.Service;
[ApiDescriptionSettings(GoViewConst.GroupName, Module = "goview", Name = "sys", Order = 100, Description = "系统登录")]
public class GoViewSysService : IDynamicApiController
{
private readonly SysAuthService _sysAuthService;
private readonly SqlSugarRepository<SysUser> _sysUserRep;
private readonly SysAuthService _sysAuthService;
private readonly SysCacheService _sysCacheService;
public GoViewSysService(SysAuthService sysAuthService,
SqlSugarRepository<SysUser> sysUserRep)
public GoViewSysService(SqlSugarRepository<SysUser> sysUserRep,
SysAuthService sysAuthService,
SysCacheService sysCacheService)
{
_sysAuthService = sysAuthService;
_sysUserRep = sysUserRep;
_sysAuthService = sysAuthService;
_sysCacheService = sysCacheService;
}
/// <summary>
@ -34,6 +37,12 @@ public class GoViewSysService : IDynamicApiController
// 设置默认租户
input.TenantId ??= SqlSugarConst.DefaultTenantId;
// 关闭默认租户验证码验证
var tenantList = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant);
var tenant = tenantList.FirstOrDefault(u => u.Id == SqlSugarConst.DefaultTenantId);
tenant.Captcha = false;
_sysCacheService.Set(CacheConst.KeyTenant, tenantList);
input.Password = CryptogramUtil.SM2Encrypt(input.Password);
var loginResult = await _sysAuthService.Login(new LoginInput()
{
@ -41,6 +50,10 @@ public class GoViewSysService : IDynamicApiController
Password = input.Password,
});
// 启用默认租户验证码验证
tenant.Captcha = true;
_sysCacheService.Set(CacheConst.KeyTenant, tenantList);
var sysUser = await _sysUserRep.AsQueryable().ClearFilter().FirstAsync(u => u.Account.Equals(input.Username));
return new GoViewLoginOutput()
{