自动退出逻辑测试

This commit is contained in:
2024-04-16 18:00:51 +08:00
parent 70ababc2d9
commit 0b0df00525
2 changed files with 24 additions and 9 deletions
@@ -67,7 +67,10 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter
if (string.IsNullOrWhiteSpace(cacheUserToken))
{
//设置当前用户最新Token
await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromMinutes(minutes));
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;
@@ -75,7 +78,17 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter
//是同一个人
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.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