😎优化登录逻辑
This commit is contained in:
parent
3d50990047
commit
de8b31224f
@ -64,7 +64,13 @@ public class AppAuthService : IDynamicApiController, ITransient
|
||||
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))
|
||||
throw Oops.Oh(ErrorCodeEnum.D0008);
|
||||
|
||||
|
||||
@ -56,7 +56,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.1191" />
|
||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1192" />
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -13,6 +13,12 @@ namespace Admin.NET.Core;
|
||||
[Description("系统错误码")]
|
||||
public enum ErrorCodeEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 租户不存在
|
||||
/// </summary>
|
||||
[ErrorCodeItemMetadata("租户不存在")]
|
||||
D0007,
|
||||
|
||||
/// <summary>
|
||||
/// 验证码错误
|
||||
/// </summary>
|
||||
|
||||
@ -59,12 +59,12 @@ public class SysAuthService : IDynamicApiController, ITransient
|
||||
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();
|
||||
// 缓存被清服务不重启这里tenant会为空,出错
|
||||
if (tenant==null && input.TenantId==0)
|
||||
var tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.FirstOrDefault(u => u.Id == input.TenantId);
|
||||
if (tenant == null)
|
||||
{
|
||||
await App.GetRequiredService<SysTenantService>().CacheTenant();
|
||||
tenant = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant)?.WhereIF(input.TenantId > 0, u => u.Id == input.TenantId).FirstOrDefault();
|
||||
await 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))
|
||||
throw Oops.Oh(ErrorCodeEnum.D0008);
|
||||
|
||||
@ -360,7 +360,7 @@ public class SysRoleService : IDynamicApiController, ITransient
|
||||
var apiList = _sysCacheService.Get<List<List<string>>>(CacheConst.KeyUserApi + userId);
|
||||
if (apiList != null) return apiList;
|
||||
|
||||
apiList = new List<List<string>>() { new(), new() };
|
||||
apiList = [[], []];
|
||||
// 超管账号获取所有接口
|
||||
if (_userManager.SuperAdmin)
|
||||
{
|
||||
@ -393,9 +393,11 @@ public class SysRoleService : IDynamicApiController, ITransient
|
||||
var roleApiList = await _sysRoleApiService.GetRoleApiList(roleIdList);
|
||||
apiList[1].AddRange(roleApiList);
|
||||
}
|
||||
|
||||
// 排序接口名称
|
||||
apiList[0].Sort();
|
||||
apiList[1].Sort();
|
||||
_sysCacheService.Set(CacheConst.KeyUserApi + userId, apiList, TimeSpan.FromDays(7)); // 缓存7天
|
||||
foreach (var lst in apiList)
|
||||
lst.Sort();
|
||||
return apiList;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "admin.net.pro",
|
||||
"type": "module",
|
||||
"version": "2.4.33",
|
||||
"lastBuildTime": "2025.03.04",
|
||||
"lastBuildTime": "2025.03.05",
|
||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||
"author": "zuohuaijun",
|
||||
"license": "MIT",
|
||||
@ -97,7 +97,7 @@
|
||||
"@vue/compiler-sfc": "^3.5.13",
|
||||
"code-inspector-plugin": "^0.20.2",
|
||||
"eslint": "^9.21.0",
|
||||
"eslint-plugin-vue": "^9.32.0",
|
||||
"eslint-plugin-vue": "^9.33.0",
|
||||
"globals": "^16.0.0",
|
||||
"less": "^4.2.2",
|
||||
"prettier": "^3.5.3",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user