using System; using Microsoft.AspNetCore.Http; namespace IRaCIS.Core.Domain.Share.AuthUser { /// /// 用户信息 /// public class UserInfo : IUserInfo { private readonly IHttpContextAccessor _accessor; public UserInfo(IHttpContextAccessor accessor) { _accessor = accessor; } /// /// 用户Id /// 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; } } /// /// 用户名 /// 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; } } } }