Exemplo n.º 1
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager)
        {
            var isAdmin = (Boolean)(UserType == UserType.Admin);
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            userIdentity.AddClaim(new Claim(ClaimKeys.FirstName.ToString(), FirstName ?? String.Empty));
            userIdentity.AddClaim(new Claim(ClaimKeys.LastName.ToString(), LastName ?? String.Empty));
            userIdentity.AddClaim(new Claim(ClaimKeys.IsPremiumMember.ToString(), Premium.GetValueOrDefault(false).ToString()));
            userIdentity.AddClaim(new Claim(ClaimKeys.Admin.ToString(), isAdmin.ToString()));

            // Add custom user claims here
            if (manager.IsInRole(Id, UserType.Admin.ToString()))
            {
                userIdentity.AddClaim(new Claim(ClaimTypes.Role, UserType.Admin.ToString()));
            }

            return(userIdentity);
        }
 public bool GetPremium()
 {
     return(Premium.GetValueOrDefault(false));
 }