live-forum/server/webapi/LiveForum/LiveForum.Code/JwtInfrastructure/JwtUserInfoModel.cs
2026-03-24 11:27:37 +08:00

78 lines
1.9 KiB
C#

using LiveForum.Code.Utility;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace LiveForum.Code.JwtInfrastructure
{
public class JwtUserInfoModel
{
/// <summary>
/// 用户id
/// </summary>
public string UserName { get; set; }
/// <summary>
///
/// </summary>
public List<Claim> Claims { get; set; }
/// <summary>
/// 过期时间
/// </summary>
public DateTime ExpireAt { get; set; }
private int? _userId = null;
/// <summary>
/// 用户Id
/// </summary>
public int UserId
{
get
{
if (_userId != null && _userId != 0)
{
return _userId ?? 0;
}
if (Claims != null && Claims.Count > 0)
{
_userId = Claims.FirstOrDefault(x => x.Type == "userId")?.Value.toint(0) ?? 0;
}
else
{
_userId = 0;
}
return _userId ?? 0;
}
}
private int? _loginType = null;
/// <summary>
/// 登录类型
/// </summary>
public int LoginType
{
get
{
if (_loginType != null && _loginType != 0)
{
return _loginType ?? 0;
}
if (Claims != null && Claims.Count > 0)
{
_loginType = Claims.FirstOrDefault(x => x.Type == "loginType")?.Value.toint(0) ?? 0;
}
else
{
_loginType = 0;
}
return _loginType ?? 0;
}
}
}
}