You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
namespace Admin.NET.Core;
|
|
|
|
/// <summary>
|
|
/// 当前登录用户
|
|
/// </summary>
|
|
public class UserManager : IScoped
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private long _tenantId;
|
|
|
|
public long UserId
|
|
{
|
|
get => long.Parse(_httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.UserId)?.Value);
|
|
}
|
|
|
|
public long TenantId
|
|
{
|
|
get
|
|
{
|
|
var tId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.TenantId)?.Value;
|
|
return string.IsNullOrWhiteSpace(tId) ? _tenantId : long.Parse(tId);
|
|
}
|
|
set => _tenantId = value;
|
|
}
|
|
|
|
public string Account
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.Account)?.Value;
|
|
}
|
|
|
|
public string RealName
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.RealName)?.Value;
|
|
}
|
|
|
|
public bool SuperAdmin
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.AccountType)?.Value == ((int)AccountTypeEnum.SuperAdmin).ToString();
|
|
}
|
|
|
|
public long OrgId
|
|
{
|
|
get
|
|
{
|
|
var orgId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.OrgId)?.Value;
|
|
return string.IsNullOrWhiteSpace(orgId) ? 0 : long.Parse(orgId);
|
|
}
|
|
}
|
|
|
|
public string OpenId
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimConst.OpenId)?.Value;
|
|
}
|
|
|
|
public UserManager(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
}
|