make
This commit is contained in:
parent
4decb3d35d
commit
8e9caee653
|
|
@ -15,9 +15,11 @@ using System.Linq;
|
|||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using CoreCms.Net.Auth.Policys;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
|
@ -167,7 +169,7 @@ namespace CoreCms.Net.Auth
|
|||
issuer,//发行人
|
||||
audience,//听众
|
||||
signingCredentials,//签名凭据
|
||||
expiration: TimeSpan.FromSeconds(60 * 60 * 24)//接口的过期时间
|
||||
expiration: TimeSpan.FromMinutes(60 * 2)//接口的过期时间
|
||||
);
|
||||
#endregion
|
||||
|
||||
|
|
@ -188,7 +190,7 @@ namespace CoreCms.Net.Auth
|
|||
ValidateAudience = true, //是否验证Audience
|
||||
ValidAudience = audience,//订阅人
|
||||
ValidateLifetime = true, //是否验证失效时间
|
||||
ClockSkew = TimeSpan.FromSeconds(60),
|
||||
ClockSkew = TimeSpan.FromMinutes(60 * 1),
|
||||
RequireExpirationTime = true,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -646,6 +646,49 @@ namespace CoreCms.Net.Services
|
|||
return jm;
|
||||
}
|
||||
|
||||
|
||||
public async Task<WebApiCallBack> AnonymousLogin(int user_id)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
var userInfo = await _dal.QueryByClauseAsync(p => p.id == user_id);
|
||||
if (userInfo != null)
|
||||
{
|
||||
|
||||
if (userInfo.status == (int)GlobalEnumVars.UserStatus.正常)
|
||||
{
|
||||
var claims = new List<Claim> {
|
||||
new Claim(ClaimTypes.Name, userInfo.nickName),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, userInfo.id.ToString()),
|
||||
new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_permissionRequirement.Expiration.TotalSeconds).ToString()) };
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
jm.status = true;
|
||||
jm.msg = "注册成功";
|
||||
jm.data = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//录入登录日志
|
||||
var log = new CoreCmsUserLog();
|
||||
log.userId = userInfo.id;
|
||||
log.state = (int)GlobalEnumVars.UserLogTypes.登录;
|
||||
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
|
||||
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
|
||||
log.createTime = DateTime.Now;
|
||||
log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString();
|
||||
await _userLogServices.InsertAsync(log);
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code11022;
|
||||
return jm;
|
||||
}
|
||||
|
||||
}
|
||||
return new WebApiCallBack()
|
||||
{
|
||||
status = false,
|
||||
msg = "用户不存在"
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user