Exemplo n.º 1
0
        /// <summary>
        /// 获取当前用户Id。
        /// </summary>
        /// <param name="state">当前验证状态。</param>
        /// <returns>当前用户Id。</returns>
        public static int GetUserId(this AuthenticationState state)
        {
            var value = state.GetClaimValue(ClaimTypes.NameIdentifier);

            if (int.TryParse(value, out var id))
            {
                return(id);
            }
            return(0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取当前用户最高级角色。
 /// </summary>
 /// <param name="state">当前验证状态。</param>
 /// <returns>当前用户最高级角色。</returns>
 public static string GetRoleName(this AuthenticationState state)
 {
     return(state.GetClaimValue(ClaimTypes.PrimarySid));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 获取当前用户电子邮件。
 /// </summary>
 /// <param name="state">当前验证状态。</param>
 /// <returns>当前用户电子邮件。</returns>
 public static string GetEmail(this AuthenticationState state)
 {
     return(state.GetClaimValue(ClaimTypes.Email));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 获取当前用户昵称。
 /// </summary>
 /// <param name="state">当前验证状态。</param>
 /// <returns>当前用户昵称。</returns>
 public static string GetNickName(this AuthenticationState state)
 {
     return(state.GetClaimValue(ClaimTypes.Surname));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 获取当前用户头像。
 /// </summary>
 /// <param name="state">当前验证状态。</param>
 /// <returns>当前用户头像。</returns>
 public static string GetAvatar(this AuthenticationState state)
 {
     return(state.GetClaimValue(ClaimTypes.Uri));
 }