[前台] 修改前台api jwttoken

This commit is contained in:
dev02 2023-05-10 15:34:15 +08:00
parent 279950b63e
commit 398acd2a74

View File

@ -48,49 +48,49 @@ namespace FrontendWebApi.ApiControllers
ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");
ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
EDFunction edFunction = new EDFunction();
//myUser = new JwtGet()
//{
// account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(),
// email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(),
// full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(),
// exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
// nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
// userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(),
//};
myUser = new JwtGet()
{
account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(),
email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(),
full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(),
exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(),
};
//if (myUser.exp == 0)
//{
// jwt_str = "Jwt Token不合法";
// jwtlife = false;
// filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
//}
//else
//{
// if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
// {
// jwtlife = true;
// JwtLogin jwtLoing = new JwtLogin()
// {
// account = myUser.account,
// email = myUser.email,
// full_name = myUser.full_name,
// userinfo_guid = myUser.userinfo_guid
// };
// jwt_str = jwt.GenerateToken(jwtLoing).token;
// }
//}
//if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
//{
// jwtlife = true;
// JwtLogin jwtLoing = new JwtLogin()
// {
// account ="webUser",
// email = "webUser@gmail.com",
// full_name = "webUser",
// userinfo_guid = "6ac24708-3a40-4199-88c5-22df310cd1a8"
// };
// jwt_str = jwt.GenerateToken(jwtLoing).token;
//}
if (myUser.exp == 0)
{
jwt_str = "Jwt Token不合法";
jwtlife = false;
filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
}
else
{
if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
{
jwtlife = true;
JwtLogin jwtLoing = new JwtLogin()
{
account = myUser.account,
email = myUser.email,
full_name = myUser.full_name,
userinfo_guid = myUser.userinfo_guid
};
jwt_str = jwt.GenerateToken(jwtLoing).token;
}
}
if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
{
jwtlife = true;
JwtLogin jwtLoing = new JwtLogin()
{
account = "webUser",
email = "webUser@gmail.com",
full_name = "webUser",
userinfo_guid = "6ac24708-3a40-4199-88c5-22df310cd1a8"
};
jwt_str = jwt.GenerateToken(jwtLoing).token;
}
base.OnActionExecuting(filterContext);
}
}