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

            Assert.IsTrue(principal.IsInRole("Agent"));
        }
예제 #2
0
파일: Users.cs 프로젝트: robgray/Tucana
        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;
            }
        }