コード例 #1
0
 public void DeleteUser(User userToDelete)
 {
     if (_connectionFactory != null)
     {
         using (var conn = _connectionFactory.Get())
         {
             conn.Run(_table.Filter(t => t.Id == userToDelete.Id).Delete());
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Create a MembershipUser object from a user object.
        /// </summary>
        /// <param name="u">User Object.</param>
        /// <returns>MembershipUser object.</returns>
        private MembershipUser GetUserFromObject(User u)
        {
            var creationDate = (DateTime)u.CreationDate;
            var lastLoginDate = new DateTime();
            if (u.LastLoginDate != null)
            {
                lastLoginDate = (DateTime)u.LastLoginDate;
            }
            var lastActivityDate = new DateTime();
            if (u.LastActivityDate != null)
            {
                lastActivityDate = (DateTime)u.LastActivityDate;
            }
            var lastPasswordChangedDate = new DateTime();
            if (u.LastPasswordChangedDate != null)
            {
                lastPasswordChangedDate = (DateTime)u.LastPasswordChangedDate;
            }
            var lastLockedOutDate = new DateTime();
            if (u.LastLockedOutDate != null)
            {
                lastLockedOutDate = (DateTime)u.LastLockedOutDate;
            }

            var membershipUser = new MembershipUser(
                Name,
                u.UserName,
                u.Id,
                u.EMail,
                u.PasswordQuestion,
                u.Comment,
                u.IsApproved,
                u.IsLockedOut,
                creationDate,
                lastLoginDate,
                lastActivityDate,
                lastPasswordChangedDate,
                lastLockedOutDate
                );
            return membershipUser;
        }
コード例 #3
0
 /// <summary>
 /// Create a new user.
 /// </summary>
 /// <param name="username">User name.</param>
 /// <param name="password">Password.</param>
 /// <param name="email">Email address.</param>
 /// <param name="passwordQuestion">Security quesiton for password.</param>
 /// <param name="passwordAnswer">Security quesiton answer for password.</param>
 /// <param name="isApproved"></param>
 /// <param name="userID">User ID</param>
 /// <param name="status"></param>
 /// <returns>MembershipUser</returns>
 public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object userID, out MembershipCreateStatus status)
 {
     try
     {
         ValidateNewPasswordFormat(username, password);
     }
     catch (Exception)
     {
         status = MembershipCreateStatus.InvalidPassword;
         return null;
     }
     if (DuplicatesEmailAddress(email))
     {
         status = MembershipCreateStatus.DuplicateEmail;
         return null;
     }
     MembershipUser membershipUser = GetUser(username, false);
     if (membershipUser == null)
     {
         User u = new User();
         u.UserName = username;
         u.ApplicationName = _applicationName;
         u.Password = EncodePassword(password);
         u.EMail = email;
         u.PasswordQuestion = passwordQuestion;
         u.PasswordAnswer = EncodePassword(passwordAnswer);
         u.IsApproved = isApproved;
         u.Comment = String.Empty;
         u.CreationDate = DateTime.Now;
         try
         {
             UserRepo.SaveUser(u);
             status = MembershipCreateStatus.Success;
         }
         catch (Exception ex)
         {
             throw new MemberAccessException("Error processing membership data - " + ex.Message);
         }
         return GetUser(username, false);
     }
     else
     {
         status = MembershipCreateStatus.DuplicateUserName;
     }
     return null;
 }
コード例 #4
0
 public static List<User> GetStubUsers(int numUsers)
 {
     var uList = new List<User>();
     for (int i = 0; i < numUsers; i++)
     {
         var u = new User();
         u.CreationDate = DateTime.Now;
         u.UserName = "******" + i;
         //u.Id = new Guid();
         uList.Add(u);
     }
     return uList;
 }
コード例 #5
0
        public static IUserRepository GetMockRepository()
        {
            User goodUser = new User()
            {
                Password = "******",
                IsApproved = true,
                CreationDate = DateTime.Now,
                PasswordAnswer = "GoodAnswer",
                LastLockedOutDate = DateTime.Now,
                LastPasswordChangedDate = DateTime.Now,
                LastLoginDate = DateTime.Now,
                UserName = "******"
            };

            var mockRepo = MockRepository.GenerateMock<IUserRepository>();
            mockRepo.Stub(v => v.GetUserByName("GoodUser", null)).Return(goodUser);
            mockRepo.Stub(v => v.GetUserByName("LockedUser", null)).Return(new User() { IsLockedOut = true });
            mockRepo.Stub(v => v.GetUserByName("BadAnswerUser", null)).Return(new User() { PasswordAnswer = "GoodAnswer", Password = "******" });
            mockRepo.Stub(v => v.GetUserByName("EncryptUser", null)).Return(new User() { PasswordAnswer = "SerLEVf28XZ/mBLKLgqulBDfUK05rOsefCL0gd+WRDE=", Password = "******", IsApproved = true });
            mockRepo.Stub(v => v.GetUserByName("HashUser", null)).Return(new User() { PasswordAnswer = "/jGKx1DvdLPnZk1ZuQaz2fSFdws=", Password = "******", IsApproved = true });
            mockRepo.Stub(v => v.GetUserByName("NewUser", null)).Return(null);
            mockRepo.Stub(v => v.GetUserByName("ExceptionUser", null)).Throw(new Exception());
            mockRepo.Stub(v => v.GetUserByID("1")).Return(goodUser);
            mockRepo.Stub(v => v.GetUserByID("999")).Throw(new MemberAccessException());
            mockRepo.Stub(v => v.FindUsersByEMail("GoodEmail", 0, 99, null)).Return(GetStubUsers(1));
            mockRepo.Stub(v => v.FindUsersByEMail("BadEmail", 0, 99, null)).Return(new List<User>());
            mockRepo.Stub(v => v.FindUsersByEMail("DupEmail", 0, 99, null)).Return(GetStubUsers(2));
            mockRepo.Stub(v => v.FindUsersByEMail("ExceptionMail", 0, 99, null)).Throw(new Exception());
            mockRepo.Stub(v => v.FindUsersByName("GoodName", 0, 99, null)).Return(GetStubUsers(1));
            mockRepo.Stub(v => v.FindUsersByName("BadName", 0, 99, null)).Return(new List<User>());
            mockRepo.Stub(v => v.FindUsersByName("DupName", 0, 99, null)).Return(GetStubUsers(2));
            mockRepo.Stub(v => v.FindUsersByName("ExceptionMail", 0, 99, null)).Throw(new Exception());
            mockRepo.Stub(v => v.GetUserNameByEMail("NewEmail", null)).Return("");
            mockRepo.Stub(v => v.GetUserNameByEMail("DupEmail", null)).Return("DupUser");
            mockRepo.Stub(v => v.GetUserNameByEMail("ExceptionEmail", null)).Throw(new Exception());
            mockRepo.Stub(v => v.GetAllUsers(0, 99, null)).Return(GetStubUsers(2));
            mockRepo.Stub(v => v.GetAllUsers(1, 99, null)).Return(new List<User>());
            mockRepo.Stub(v => v.GetAllUsers(2, 99, null)).Throw(new Exception());
            return mockRepo;
        }
コード例 #6
0
 public void SaveUser(User userToSave)
 {
     if (_connectionFactory != null)
     {
         using (var conn = _connectionFactory.Get())
         {
             double numberReplaced = conn.Run(_table.Get(userToSave.Id).Update(o => userToSave)).Replaced;
             if (numberReplaced == 0)
             {
                 conn.Run(_table.Insert(userToSave));
             }
         }
     }
 }