修改用户权限校验

Uat_Study
hang 2022-05-26 16:26:48 +08:00
parent 8d3e892216
commit 0cfc8fc37b
2 changed files with 18 additions and 2 deletions

View File

@ -35,27 +35,43 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter
{
if (context.ActionDescriptor.EndpointMetadata.Any(item => item is IAllowAnonymous))
{
return;
//匿名访问的不处理
}
else
{
//1、用户登陆的时候设置缓存
//没有从请求中取到token
if (string.IsNullOrWhiteSpace(_userInfo.UserToken))
{
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.StatusCode = StatusCodes.Status200OK;
await context.HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(ResponseOutput.NotOk("当前请求未从Header/Url取到Token")));
}
//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.FromDays(7));
cacheUserToken = _userInfo.UserToken;
}
//是同一个人
else if (cacheUserToken == _userInfo.UserToken)
{
}
else
{

View File

@ -283,7 +283,7 @@ namespace IRaCIS.Core.Application.Contracts
TrialSiteSurveyId = dbEntity!.Id,
Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo()
{
Id = Guid.Empty,
Id = Guid.NewGuid(),
IsReviewer = false,
IsAdmin = false,
RealName = "SiteSurvey",