Example #1
0
 public MemberUserData(Member member)
 {
     Id = member.Id;
     Username = member.Email;
     DisplayName = string.Format("{0}", member.Name);
     Roles = new[] { "User" };
     Type = "User";
 }
Example #2
0
 public AdminUserData(Member member)
 {
     Id = member.Id;
     Username = member.Email;
     DisplayName = string.Format("{0}", member.Name);
     Roles = new string[] { "Admin" };
     Type = "Admin";
 }
        public void Authenticate(Member member)
        {
            switch (member.Role)
            {
                case MemberRole.Admin: AddFormsCookie(new UserModels.AdminUserData(member));
                    break;
                case MemberRole.User: AddFormsCookie(new UserModels.MemberUserData(member));
                    break;
            }

            var claims = new List<Claim>
                             {
                                 new Claim("Username", member.Email),
                                 new Claim(ClaimTypes.Name, member.Name),
                                 new Claim(ClaimTypes.Email, member.Email),
                                 new Claim(ClaimTypes.Role, member.Role.ToString())
                             };

            var claimsIdentity = new ClaimsIdentity(claims, "Basic", "Username", ClaimTypes.Role);
            Thread.CurrentPrincipal = new ClaimsPrincipal(claimsIdentity);
        }