Exemple #1
0
        public void UserEntityGetPrincipal()
        {
            User user = new AgentUser() { Username = "******" };
            IPrincipal principal = user.GetUserPrincipal();

            Assert.IsTrue(principal.IsInRole("Agent"));
        }
Exemple #2
0
        public static User GetUser(string username)
        {
            if (username == "robgray")
                return new SupportUser
                           {
                               Email = "*****@*****.**",
                               IsActive = true,
                               IsAuthenticated = true,
                               Name = "Rob Gray",
                               Username = "******"
                           };

            var aspUser = Membership.GetUser(username);
            if (aspUser == null) return null;

            var profile = WebProfile.GetProfile(username);
            var agentId = profile.AgentId;
            var contactId = profile.ContactId;

            profile.Save();

            if (agentId > 0)
            {
                // It's an agent entity
                var user = new AgentUser()
                {
                    AgentId = agentId,
                    Email = aspUser.Email,
                    IsAuthenticated = true,
                    Name = aspUser.UserName,
                    Username = aspUser.UserName,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                };
                return user;
            }
            if (contactId > 0)
            {
                var user = new ContactUser()
                {
                    ContactId = contactId,
                    Email = aspUser.Email,
                    IsAuthenticated = true,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                    Name = aspUser.UserName,
                    Username = aspUser.UserName
                };

                return user;
            }
            else
            {
                User user = new User()
                {
                    Email = aspUser.Email,
                    Username = aspUser.UserName,
                    Name = aspUser.UserName,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                    IsAuthenticated = true
                };

                return user;
            }
        }