😎优化登录逻辑

This commit is contained in:
zuohuaijun 2025-03-05 11:41:44 +08:00
parent 3d50990047
commit de8b31224f
6 changed files with 60 additions and 46 deletions

View File

@ -64,7 +64,13 @@ public class AppAuthService : IDynamicApiController, ITransient
throw Oops.Oh(ErrorCodeEnum.D1027); throw Oops.Oh(ErrorCodeEnum.D1027);
// 判断是否开启验证码并校验 // 判断是否开启验证码并校验
var tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.WhereIF(input.TenantId > 0, u => u.Id == input.TenantId).FirstOrDefault(); var tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.FirstOrDefault(u => u.Id == input.TenantId);
if (tenant == null)
{
await Furion.App.GetRequiredService<SysTenantService>().CacheTenant(); // 重新生成租户列表缓存
tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.FirstOrDefault(u => u.Id == input.TenantId);
if (tenant == null) throw Oops.Oh(ErrorCodeEnum.D0007);
}
if (tenant.Captcha == true && !_captcha.Validate(input.CodeId.ToString(), input.Code)) if (tenant.Captcha == true && !_captcha.Validate(input.CodeId.ToString(), input.Code))
throw Oops.Oh(ErrorCodeEnum.D0008); throw Oops.Oh(ErrorCodeEnum.D0008);

View File

@ -56,7 +56,7 @@
<PackageReference Include="SSH.NET" Version="2024.2.0" /> <PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" /> <PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" /> <PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1191" /> <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1192" />
<PackageReference Include="UAParser" Version="3.1.47" /> <PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" /> <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup> </ItemGroup>

View File

@ -13,6 +13,12 @@ namespace Admin.NET.Core;
[Description("系统错误码")] [Description("系统错误码")]
public enum ErrorCodeEnum public enum ErrorCodeEnum
{ {
/// <summary>
/// 租户不存在
/// </summary>
[ErrorCodeItemMetadata("租户不存在")]
D0007,
/// <summary> /// <summary>
/// 验证码错误 /// 验证码错误
/// </summary> /// </summary>

View File

@ -59,12 +59,12 @@ public class SysAuthService : IDynamicApiController, ITransient
if (passwordErrorTimes > passwordMaxErrorTimes) throw Oops.Oh(ErrorCodeEnum.D1027); 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(); var tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.FirstOrDefault(u => u.Id == input.TenantId);
// 缓存被清服务不重启这里tenant会为空,出错 if (tenant == null)
if (tenant==null && input.TenantId==0)
{ {
await App.GetRequiredService<SysTenantService>().CacheTenant(); await App.GetRequiredService<SysTenantService>().CacheTenant(); // 重新生成租户列表缓存
tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.WhereIF(input.TenantId > 0, u => u.Id == input.TenantId).FirstOrDefault(); tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.FirstOrDefault(u => u.Id == input.TenantId);
if (tenant == null) throw Oops.Oh(ErrorCodeEnum.D0007);
} }
if (tenant.Captcha == true && !_captcha.Validate(input.CodeId.ToString(), input.Code)) if (tenant.Captcha == true && !_captcha.Validate(input.CodeId.ToString(), input.Code))
throw Oops.Oh(ErrorCodeEnum.D0008); throw Oops.Oh(ErrorCodeEnum.D0008);

View File

@ -360,7 +360,7 @@ public class SysRoleService : IDynamicApiController, ITransient
var apiList = _sysCacheService.Get<List<List<string>>>(CacheConst.KeyUserApi + userId); var apiList = _sysCacheService.Get<List<List<string>>>(CacheConst.KeyUserApi + userId);
if (apiList != null) return apiList; if (apiList != null) return apiList;
apiList = new List<List<string>>() { new(), new() }; apiList = [[], []];
// 超管账号获取所有接口 // 超管账号获取所有接口
if (_userManager.SuperAdmin) if (_userManager.SuperAdmin)
{ {
@ -393,9 +393,11 @@ public class SysRoleService : IDynamicApiController, ITransient
var roleApiList = await _sysRoleApiService.GetRoleApiList(roleIdList); var roleApiList = await _sysRoleApiService.GetRoleApiList(roleIdList);
apiList[1].AddRange(roleApiList); apiList[1].AddRange(roleApiList);
} }
// 排序接口名称
apiList[0].Sort();
apiList[1].Sort();
_sysCacheService.Set(CacheConst.KeyUserApi + userId, apiList, TimeSpan.FromDays(7)); // 缓存7天 _sysCacheService.Set(CacheConst.KeyUserApi + userId, apiList, TimeSpan.FromDays(7)); // 缓存7天
foreach (var lst in apiList)
lst.Sort();
return apiList; return apiList;
} }

View File

@ -2,7 +2,7 @@
"name": "admin.net.pro", "name": "admin.net.pro",
"type": "module", "type": "module",
"version": "2.4.33", "version": "2.4.33",
"lastBuildTime": "2025.03.04", "lastBuildTime": "2025.03.05",
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架", "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
"author": "zuohuaijun", "author": "zuohuaijun",
"license": "MIT", "license": "MIT",
@ -97,7 +97,7 @@
"@vue/compiler-sfc": "^3.5.13", "@vue/compiler-sfc": "^3.5.13",
"code-inspector-plugin": "^0.20.2", "code-inspector-plugin": "^0.20.2",
"eslint": "^9.21.0", "eslint": "^9.21.0",
"eslint-plugin-vue": "^9.32.0", "eslint-plugin-vue": "^9.33.0",
"globals": "^16.0.0", "globals": "^16.0.0",
"less": "^4.2.2", "less": "^4.2.2",
"prettier": "^3.5.3", "prettier": "^3.5.3",