修改角色禁用

Uat_IRC_Net8
hang 2025-01-10 14:05:05 +08:00
parent 4cdf94d29c
commit 2509e26aae
5 changed files with 33 additions and 3 deletions

View File

@ -153,7 +153,6 @@ namespace IRaCIS.Api.Controllers
// 验证阅片休息时间
await readingImageTaskService.ResetReadingRestTime(userId);
await _fusionCache.SetAsync(CacheKeys.UserToken(userId), loginReturn.JWTStr, TimeSpan.FromDays(7));
await _fusionCache.SetAsync(CacheKeys.UserAutoLoginOut(userId), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes));
@ -279,7 +278,7 @@ namespace IRaCIS.Api.Controllers
// 验证阅片休息时间
await readingImageTaskService.ResetReadingRestTime(returnModel.Data.BasicInfo.IdentityUserId);
await _fusionCache.SetAsync(CacheKeys.UserToken(userId), returnModel.Data.JWTStr, TimeSpan.FromDays(7));
await _fusionCache.SetAsync(CacheKeys.UserAutoLoginOut(userId), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes));
}

View File

@ -57,7 +57,7 @@
"OpenTrialRelationDelete": true,
"OpenLoginLimit": false,
"OpenLoginLimit": true,
"LoginMaxFailCount": 5,

View File

@ -93,6 +93,21 @@ public class LimitUserRequestAuthorization(
}
//用户或者角色禁用,那么操作的人退出
var isDisable = await _fusionCache.GetOrDefaultAsync<bool>(CacheKeys.UserDisable(_userInfo.IdentityUserId),false);
var isRoleDisable = await _fusionCache.GetOrDefaultAsync<bool>(CacheKeys.UserRoleDisable(_userInfo.UserRoleId),false);
if (isDisable == true || isRoleDisable == true)
{
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.StatusCode = StatusCodes.Status403Forbidden;
// 用户或者角色被禁用。
context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["LimitUser_AccountOrRoleDisable"], ApiResponseCodeEnum.AutoLoginOut));
}
}
}

View File

@ -27,6 +27,11 @@ public static class CacheKeys
//超时没请求接口自动退出
public static string UserAutoLoginOut(Guid userId) => $"UserAutoLoginOut:{userId}";
public static string UserDisable(Guid userId) => $"UserDisable:{userId}";
public static string UserRoleDisable(Guid userRoleId) => $"UserRoleDisable:{userRoleId}";
/// <summary>
/// 用户登录错误 限制登录
/// </summary>

View File

@ -615,6 +615,9 @@ namespace IRaCIS.Core.Application.Service
{
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = model.Id, OptType = model.Status == UserStateEnum.Enable ? UserOptType.AccountEnable : UserOptType.AccountLocked }, true);
await _fusionCache.SetAsync(CacheKeys.UserDisable(user.Id), model.Status == UserStateEnum.Disable, TimeSpan.FromHours(1));
}
@ -636,6 +639,8 @@ namespace IRaCIS.Core.Application.Service
if (find != null)
{
find.IsUserRoleDisabled = role.IsUserRoleDisabled;
await _fusionCache.SetAsync(CacheKeys.UserRoleDisable(find.Id), find.IsUserRoleDisabled, TimeSpan.FromHours(1));
}
else
{
@ -690,6 +695,9 @@ namespace IRaCIS.Core.Application.Service
if (find != null)
{
find.IsUserRoleDisabled = role.IsUserRoleDisabled;
await _fusionCache.SetAsync(CacheKeys.UserRoleDisable(find.Id), find.IsUserRoleDisabled, TimeSpan.FromHours(1));
}
else
{
@ -1149,6 +1157,9 @@ namespace IRaCIS.Core.Application.Service
{
var jwt = _tokenService.GetToken(userTokenInfo);
await _fusionCache.SetAsync(CacheKeys.UserToken(userTokenInfo.IdentityUserId), jwt, TimeSpan.FromDays(7));
return jwt;
}
else