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.
 
 

125 lines
2.9 KiB

using Microsoft.AspNetCore.Http;
using Znyc.CloudCar.Auth.Policys;
using Znyc.CloudCar.Utility.Extensions;
namespace Znyc.CloudCar.Auth.HttpContextUser
{
public class AspNetUser : IHttpContextUser
{
private readonly IHttpContextAccessor _accessor;
public AspNetUser(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary>
/// 用户Id
/// </summary>
public virtual long Id
{
get
{
System.Security.Claims.Claim id = _accessor?.HttpContext?.User?.FindFirst(Claims.UserId);
if (id != null && id.Value.NotNull())
{
return id.Value.ObjectToLong();
}
return 0;
}
}
/// <summary>
/// 权限Id
/// </summary>
public string RoleId
{
get
{
System.Security.Claims.Claim name = _accessor?.HttpContext?.User?.FindFirst(Claims.RoleId);
if (name != null && name.Value.NotNull())
{
return name.Value;
}
return "";
}
}
/// <summary>
/// 昵称
/// </summary>
public string UserName
{
get
{
System.Security.Claims.Claim name = _accessor?.HttpContext?.User?.FindFirst(Claims.UserName);
if (name != null && name.Value.NotNull())
{
return name.Value;
}
return "";
}
}
/// <summary>
/// OpenId
/// </summary>
public string OpenId
{
get
{
System.Security.Claims.Claim name = _accessor?.HttpContext?.User?.FindFirst(Claims.OpenId);
if (name != null && name.Value.NotNull())
{
return name.Value;
}
return "";
}
}
/// <summary>
/// UnionId
/// </summary>
public string UnionId
{
get
{
System.Security.Claims.Claim name = _accessor?.HttpContext?.User?.FindFirst(Claims.UnionId);
if (name != null && name.Value.NotNull())
{
return name.Value;
}
return "";
}
}
/// <summary>
/// SessionKey
/// </summary>
public string SessionKey
{
get
{
System.Security.Claims.Claim name = _accessor?.HttpContext?.User?.FindFirst(Claims.SessionKey);
if (name != null && name.Value.NotNull())
{
return name.Value;
}
return "";
}
}
}
}