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,8 +692,12 @@ 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

@ -38,6 +38,8 @@ namespace IRaCIS.Core.Infrastructure.Extention
//在其他地方登陆,被迫下线
LoginInOtherPlace = -1,
AutoLoginOut = -2,
//没有带token访问未登陆
NoToken = 10,