diff --git a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs index 641bcbfa..9dd5d5ab 100644 --- a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs +++ b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs @@ -63,13 +63,14 @@ public class AppAuthService : IDynamicApiController, ITransient if (passwordErrorTimes >= passwdMaxErrorTimes) throw Oops.Oh(ErrorCodeEnum.D1027); - // 是否开启验证码 - if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysCaptcha)) - { - // 判断验证码 - if (!_captcha.Validate(input.CodeId.ToString(), input.Code)) - throw Oops.Oh(ErrorCodeEnum.D0008); - } + // 判断是否开启验证码并校验 + var tenant = _sysCacheService.Get>(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); + + // 租户是否被禁用 + if (tenant != null && tenant.Status == StatusEnum.Disable) + throw Oops.Oh(ErrorCodeEnum.Z1003); // 账号是否存在 var user = await _sysUserRep.AsQueryable().Includes(t => t.SysOrg).ClearFilter().FirstAsync(u => u.Account.Equals(input.Account)); @@ -79,11 +80,6 @@ public class AppAuthService : IDynamicApiController, ITransient if (user.Status == StatusEnum.Disable) throw Oops.Oh(ErrorCodeEnum.D1017); - // 租户是否被禁用 - var tenant = await _sysUserRep.ChangeRepository>().GetByIdAsync(user.TenantId); - if (tenant != null && tenant.Status == StatusEnum.Disable) - throw Oops.Oh(ErrorCodeEnum.Z1003); - // 国密SM2解密(前端密码传输SM2加密后的) try { diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index a35448c0..dc45dac9 100644 --- a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj +++ b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj @@ -20,9 +20,9 @@ - - - + + + @@ -44,11 +44,11 @@ - + - + diff --git a/Admin.NET/Admin.NET.Core/Const/ConfigConst.cs b/Admin.NET/Admin.NET.Core/Const/ConfigConst.cs index a563ab9b..4dec0a78 100644 --- a/Admin.NET/Admin.NET.Core/Const/ConfigConst.cs +++ b/Admin.NET/Admin.NET.Core/Const/ConfigConst.cs @@ -41,15 +41,15 @@ public class ConfigConst /// public const string SysSingleLogin = "sys_single_login"; - /// - /// 登录二次验证 - /// - public const string SysSecondVer = "sys_second_ver"; + ///// + ///// 登录二次验证 + ///// + //public const string SysSecondVer = "sys_second_ver"; - /// - /// 图形验证码 - /// - public const string SysCaptcha = "sys_captcha"; + ///// + ///// 图形验证码 + ///// + //public const string SysCaptcha = "sys_captcha"; /// /// Token过期时间 diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs b/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs index 5a9d832d..5f05fc67 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs @@ -28,8 +28,7 @@ public class LoginInput /// /// 租户Id /// - //[Required(ErrorMessage = "租户Id不能为空")] - public long TenantId { get; set; } + public long TenantId { get; set; } = SqlSugarConst.DefaultTenantId; /// /// 验证码Id diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs index 4e927840..a3a9f224 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -59,7 +59,9 @@ public class SysAuthService : IDynamicApiController, ITransient if (passwordErrorTimes > passwordMaxErrorTimes) throw Oops.Oh(ErrorCodeEnum.D1027); // 判断是否开启验证码并校验 - if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysCaptcha) && !_captcha.Validate(input.CodeId.ToString(), input.Code)) throw Oops.Oh(ErrorCodeEnum.D0008); + var tenant = _sysCacheService.Get>(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); // 获取并验证账号 var user = await GetLoginUser(input.TenantId, account: input.Account); @@ -385,7 +387,11 @@ public class SysAuthService : IDynamicApiController, ITransient { try { - _sysCacheService.Set($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}", false); + // 关闭默认租户验证码验证 + var tenantList = _sysCacheService.Get>(CacheConst.KeyTenant); + var tenant = tenantList.FirstOrDefault(u => u.Id == SqlSugarConst.DefaultTenantId); + tenant.Captcha = false; + _sysCacheService.Set(CacheConst.KeyTenant, tenantList); await Login(new LoginInput { @@ -394,7 +400,9 @@ public class SysAuthService : IDynamicApiController, ITransient TenantId = SqlSugarConst.DefaultTenantId }); - _sysCacheService.Remove($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}"); + // 启用默认租户验证码验证 + tenant.Captcha = true; + _sysCacheService.Set(CacheConst.KeyTenant, tenantList); return 200; } diff --git a/Admin.NET/Plugins/Admin.NET.Plugin.GoView/Service/GoViewSys/GoViewSysService.cs b/Admin.NET/Plugins/Admin.NET.Plugin.GoView/Service/GoViewSys/GoViewSysService.cs index e3449b23..1add91f9 100644 --- a/Admin.NET/Plugins/Admin.NET.Plugin.GoView/Service/GoViewSys/GoViewSysService.cs +++ b/Admin.NET/Plugins/Admin.NET.Plugin.GoView/Service/GoViewSys/GoViewSysService.cs @@ -13,16 +13,16 @@ 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 _sysUserRep; + private readonly SysAuthService _sysAuthService; private readonly SysCacheService _sysCacheService; - public GoViewSysService(SysAuthService sysAuthService, - SqlSugarRepository sysUserRep, + public GoViewSysService(SqlSugarRepository sysUserRep, + SysAuthService sysAuthService, SysCacheService sysCacheService) { - _sysAuthService = sysAuthService; _sysUserRep = sysUserRep; + _sysAuthService = sysAuthService; _sysCacheService = sysCacheService; } @@ -37,7 +37,11 @@ public class GoViewSysService : IDynamicApiController // 设置默认租户 input.TenantId ??= SqlSugarConst.DefaultTenantId; - _sysCacheService.Set($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}", false); + // 关闭默认租户验证码验证 + var tenantList = _sysCacheService.Get>(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() @@ -46,7 +50,9 @@ public class GoViewSysService : IDynamicApiController Password = input.Password, }); - _sysCacheService.Remove($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}"); + // 启用默认租户验证码验证 + tenant.Captcha = true; + _sysCacheService.Set(CacheConst.KeyTenant, tenantList); var sysUser = await _sysUserRep.AsQueryable().ClearFilter().FirstAsync(u => u.Account.Equals(input.Username)); return new GoViewLoginOutput()