Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8

IRC_NewDev
he 2024-04-18 11:45:10 +08:00
commit 3f8d5027c8
7 changed files with 50 additions and 18 deletions

View File

@ -41,7 +41,8 @@
"OpenLoginLimit": true,
"LoginMaxFailCount": 5,
"LoginFailLockMinutes": 30
"LoginFailLockMinutes": 30,
"AutoLoginOutMinutes": 60
},
"SystemEmailSendConfig": {

View File

@ -42,7 +42,8 @@
"OpenLoginLimit": true,
"LoginMaxFailCount": 5,
"LoginFailLockMinutes": 30
"LoginFailLockMinutes": 30,
"AutoLoginOutMinutes": 60
},
"SystemEmailSendConfig": {

View File

@ -60,7 +60,8 @@
"LoginMaxFailCount": 5,
"LoginFailLockMinutes": 30
"LoginFailLockMinutes": 30,
"AutoLoginOutMinutes": 60
},
"SystemEmailSendConfig": {

View File

@ -44,7 +44,8 @@
"OpenLoginLimit": true,
"LoginMaxFailCount": 5,
"LoginFailLockMinutes": 30
"LoginFailLockMinutes": 30,
"AutoLoginOutMinutes": 60
},
"SystemEmailSendConfig": {

View File

@ -60,22 +60,43 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter
context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["LimitUser_AuthTokenMissing"]));
}
//2、在这里取缓存 进行比较 看是否有其他人进行了登陆,如果其他人登陆了,就把之前用户挤掉
var cacheUserToken = (await _provider.GetAsync<string>(_userInfo.Id.ToString())).Value;
//缓存中没有取到Token
if (string.IsNullOrWhiteSpace(cacheUserToken))
{
//设置当前用户最新Token
await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromMinutes(minutes));
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));
}
//是同一个人
else if (cacheUserToken == _userInfo.UserToken)
{
await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromMinutes(minutes));
var cacheTime = (await _provider.GetAsync<string>($"{_userInfo.Id.ToString()}_Online")).Value;
//过期了 需要自动退出
if (string.IsNullOrEmpty(cacheTime))
{
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.StatusCode = StatusCodes.Status403Forbidden;
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

View File

@ -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);
}

View File

@ -18,7 +18,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
BusinessValidationFailed = 2,
//数据不存在
DataNotExist=3,
DataNotExist = 3,
//程序异常 相当于之前的 IsSuccess = false
ProgramException = 4,
@ -27,10 +27,10 @@ namespace IRaCIS.Core.Infrastructure.Extention
//需要提示 ,需要提示 从Result 取数据 0 可以继续处理提交 ,1 不能进行继续处理提交 ,2 刷新列表 )
NeedTips = 5,
NeedTips = 5,
CloseCurrentWindows=6,
CloseCurrentWindows = 6,
@ -38,15 +38,17 @@ namespace IRaCIS.Core.Infrastructure.Extention
//在其他地方登陆,被迫下线
LoginInOtherPlace = -1,
AutoLoginOut = -2,
//没有带token访问未登陆
NoToken=10,
NoToken = 10,
//带了Token,但是没有相应权限(该用户类型不能做)
HaveTokenNotAccess=11
HaveTokenNotAccess = 11
}
}