From 8a5fa59d265dcf721f9ee00c6580ee4a67fb3ac4 Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Fri, 28 Feb 2025 02:44:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=98=8E=E4=BF=AE=E5=A4=8D=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E8=B0=83=E6=95=B4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/App/Auth/AppAuthService.cs | 20 ++++++++----------- .../Admin.NET.Core/Admin.NET.Core.csproj | 6 +++--- Admin.NET/Admin.NET.Core/Const/ConfigConst.cs | 16 +++++++-------- .../Service/Auth/Dto/LoginInput.cs | 3 +-- .../Service/Auth/SysAuthService.cs | 10 ++++------ .../Service/GoViewSys/GoViewSysService.cs | 9 +-------- 6 files changed, 25 insertions(+), 39 deletions(-) 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 571db8c9..e02579f5 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 @@ - - - + + + 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..65f37483 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -58,8 +58,10 @@ public class SysAuthService : IDynamicApiController, ITransient if (passwordMaxErrorTimes < 1) passwordMaxErrorTimes = 5; 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,8 +387,6 @@ public class SysAuthService : IDynamicApiController, ITransient { try { - _sysCacheService.Set($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}", false); - await Login(new LoginInput { Account = auth.UserName, @@ -394,8 +394,6 @@ public class SysAuthService : IDynamicApiController, ITransient TenantId = SqlSugarConst.DefaultTenantId }); - _sysCacheService.Remove($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}"); - return 200; } catch (Exception) 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..c0d02b78 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 @@ -15,15 +15,12 @@ public class GoViewSysService : IDynamicApiController { private readonly SysAuthService _sysAuthService; private readonly SqlSugarRepository _sysUserRep; - private readonly SysCacheService _sysCacheService; public GoViewSysService(SysAuthService sysAuthService, - SqlSugarRepository sysUserRep, - SysCacheService sysCacheService) + SqlSugarRepository sysUserRep) { _sysAuthService = sysAuthService; _sysUserRep = sysUserRep; - _sysCacheService = sysCacheService; } /// @@ -37,8 +34,6 @@ public class GoViewSysService : IDynamicApiController // 设置默认租户 input.TenantId ??= SqlSugarConst.DefaultTenantId; - _sysCacheService.Set($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}", false); - input.Password = CryptogramUtil.SM2Encrypt(input.Password); var loginResult = await _sysAuthService.Login(new LoginInput() { @@ -46,8 +41,6 @@ public class GoViewSysService : IDynamicApiController Password = input.Password, }); - _sysCacheService.Remove($"{CacheConst.KeyConfig}{ConfigConst.SysCaptcha}"); - var sysUser = await _sysUserRep.AsQueryable().ClearFilter().FirstAsync(u => u.Account.Equals(input.Username)); return new GoViewLoginOutput() { From 39c7c03d06f7f622e84fda81b7b6ee05c59956ed Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Fri, 28 Feb 2025 11:27:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=98=8E=E8=B0=83=E6=95=B4swagger?= =?UTF-8?q?=E5=92=8C=E5=A4=A7=E5=B1=8F=E7=99=BB=E5=BD=95=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=A7=9F=E6=88=B7=E9=AA=8C=E8=AF=81=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Core/Admin.NET.Core.csproj | 8 +++---- .../Service/Auth/SysAuthService.cs | 12 ++++++++++- .../Service/GoViewSys/GoViewSysService.cs | 21 +++++++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index e02579f5..4566871d 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 @@ - - - + + + @@ -48,7 +48,7 @@ - + diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs index 65f37483..a3a9f224 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -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>(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>(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) 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 c0d02b78..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,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 _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; } /// @@ -34,6 +37,12 @@ public class GoViewSysService : IDynamicApiController // 设置默认租户 input.TenantId ??= SqlSugarConst.DefaultTenantId; + // 关闭默认租户验证码验证 + 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() { @@ -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() { From 144fd6ead25978763c7365670bb9e84bd4722c3f Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Fri, 28 Feb 2025 13:20:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=98=8E=E5=8D=87=E7=BA=A7sqlsugar=20v5?= =?UTF-8?q?.1.4.180?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index 4566871d..cc622db9 100644 --- a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj +++ b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj @@ -44,7 +44,7 @@ - +