From 2509e26aae4868fa4f8b7c07fd80f6d8c98d6c72 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 10 Jan 2025 14:05:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2=E7=A6=81?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/Controllers/ExtraController.cs | 3 +-- IRaCIS.Core.API/appsettings.Test_IRC.json | 2 +- .../LimitUserRequestAuthorization.cs | 15 +++++++++++++++ IRaCIS.Core.Application/Helper/CacheHelper.cs | 5 +++++ .../Service/Management/UserService.cs | 11 +++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index f15e31eca..0aaba76b6 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -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)); } diff --git a/IRaCIS.Core.API/appsettings.Test_IRC.json b/IRaCIS.Core.API/appsettings.Test_IRC.json index 8ac7cdae1..da8225643 100644 --- a/IRaCIS.Core.API/appsettings.Test_IRC.json +++ b/IRaCIS.Core.API/appsettings.Test_IRC.json @@ -57,7 +57,7 @@ "OpenTrialRelationDelete": true, - "OpenLoginLimit": false, + "OpenLoginLimit": true, "LoginMaxFailCount": 5, diff --git a/IRaCIS.Core.Application/BusinessFilter/LegacyController/LimitUserRequestAuthorization.cs b/IRaCIS.Core.Application/BusinessFilter/LegacyController/LimitUserRequestAuthorization.cs index bf1eb6baf..c720cd597 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LegacyController/LimitUserRequestAuthorization.cs +++ b/IRaCIS.Core.Application/BusinessFilter/LegacyController/LimitUserRequestAuthorization.cs @@ -93,6 +93,21 @@ public class LimitUserRequestAuthorization( } + //用户或者角色禁用,那么操作的人退出 + + var isDisable = await _fusionCache.GetOrDefaultAsync(CacheKeys.UserDisable(_userInfo.IdentityUserId),false); + + var isRoleDisable = await _fusionCache.GetOrDefaultAsync(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)); + } + } } diff --git a/IRaCIS.Core.Application/Helper/CacheHelper.cs b/IRaCIS.Core.Application/Helper/CacheHelper.cs index 50deb6ccf..fa33c859e 100644 --- a/IRaCIS.Core.Application/Helper/CacheHelper.cs +++ b/IRaCIS.Core.Application/Helper/CacheHelper.cs @@ -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}"; + /// /// 用户登录错误 限制登录 /// diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index c4b21438e..0e18298af 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -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