CostCalculationItem/IRaCIS.Core.Domain.Share/AuthUser/UserInfo.cs

79 lines
1.9 KiB
C#

using System;
using Microsoft.AspNetCore.Http;
namespace IRaCIS.Core.Domain.Share.AuthUser
{
/// <summary>
/// 用户信息
/// </summary>
public class UserInfo : IUserInfo
{
private readonly IHttpContextAccessor _accessor;
public UserInfo(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary>
/// 用户Id
/// </summary>
public Guid Id
{
get {
var id = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.UserId);
if (id != null && !string.IsNullOrEmpty(id.Value))
{
return Guid.Parse(id.Value);
}
return Guid.Empty;
}
}
/// <summary>
/// 用户名
/// </summary>
public string UserName
{
get {
var name = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.UserName);
if (name != null && !string.IsNullOrEmpty(name.Value))
{
return name.Value;
}
return "";
}
}
public string RealName
{
get {
var name = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.RealName);
if (name != null && !string.IsNullOrEmpty(name.Value))
{
return name.Value;
}
return "";
}
}
public string ReviewerCode
{
get {
var reviewerCode = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.ReviewerCode);
if (reviewerCode != null && !string.IsNullOrEmpty(reviewerCode.Value))
{
return reviewerCode.Value;
}
return string.Empty;
}
}
}
}