diff --git a/IRaCIS.Core.Application/BusinessFilter/LimitUserRequestAuthorization.cs b/IRaCIS.Core.Application/BusinessFilter/LimitUserRequestAuthorization.cs index 3b646880f..911501c48 100644 --- a/IRaCIS.Core.Application/BusinessFilter/LimitUserRequestAuthorization.cs +++ b/IRaCIS.Core.Application/BusinessFilter/LimitUserRequestAuthorization.cs @@ -60,37 +60,43 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["LimitUser_AuthTokenMissing"])); } + + //2、在这里取缓存 进行比较 看是否有其他人进行了登陆,如果其他人登陆了,就把之前用户挤掉 var cacheUserToken = (await _provider.GetAsync(_userInfo.Id.ToString())).Value; + + //缓存中没有取到Token if (string.IsNullOrWhiteSpace(cacheUserToken)) { + cacheUserToken = _userInfo.UserToken; + //设置当前用户最新Token await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromDays(7)); - await _provider.SetAsync($"{_userInfo.Id.ToString()}_Online", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(minutes)); - cacheUserToken = _userInfo.UserToken; - } //是同一个人 else if (cacheUserToken == _userInfo.UserToken) { + var cacheTime = (await _provider.GetAsync($"{_userInfo.Id.ToString()}_Online")).Value; //过期了 需要自动退出 - if(string.IsNullOrEmpty(cacheTime)) + if (string.IsNullOrEmpty(cacheTime)) { context.HttpContext.Response.ContentType = "application/json"; context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; - context.Result = new JsonResult(ResponseOutput.NotOk("登录无操作超时自动退出"), ApiResponseCodeEnum.AutoLoginOut); + context.Result = new JsonResult(ResponseOutput.NotOk("登录无操作超时自动退出", ApiResponseCodeEnum.AutoLoginOut)); + } else { await _provider.SetAsync($"{_userInfo.Id.ToString()}_Online", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(minutes)); } + } else diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 438b88d3e..95c6f0a69 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -15,6 +15,7 @@ using Medallion.Threading; using EasyCaching.Core; using IRaCIS.Core.Application.Contracts; using LoginReturnDTO = IRaCIS.Application.Contracts.LoginReturnDTO; +using OfficeOpenXml.FormulaParsing.Utilities; namespace IRaCIS.Application.Services { @@ -691,10 +692,14 @@ namespace IRaCIS.Application.Services userLoginReturnModel.BasicInfo = loginUser; - // 登录 清除缓存 - _cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString()); - + // 登录 清除缓存 + //_cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString()); + + var userId = loginUser.Id; + await _cache.SetAsync($"{userId.ToString()}_Online", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes)); + + return ResponseOutput.Ok(userLoginReturnModel); }