예제 #1
0
        public BasicResult ChangePassword(long userId, string password)
        {
            if (!IsValidPassword(password))
            {
                return(BasicResult.FailResult("Invalid Password (Must: contain 1 uppercase, contain 1 number and be 8-15 characters long)"));
            }

            var user = GetById(userId);

            if (user == null)
            {
                return(BasicResult.FailResult("No user with that id exists"));
            }

            string savedPasswordHash = HashPassword(password);

            user.Password = savedPasswordHash;

            var success = _repository.Update(user);

            if (!success)
            {
                return(BasicResult.FailResult("Database Error"));
            }

            return(BasicResult.SuccessResult());
        }
예제 #2
0
        public BasicResult Update(long userId, string email, string fullName, DateTime dateOfBirth)
        {
            var user = GetById(userId);

            if (user == null)
            {
                return(BasicResult.FailResult("No user with that id exists"));
            }

            user.Email       = email;
            user.FullName    = fullName;
            user.DateOfBirth = dateOfBirth;

            var validationError = user.ValidationErrors().FirstOrDefault();

            if (validationError != null)
            {
                return(BasicResult.FailResult(validationError));
            }

            var userWithEmail = _repository.Find <IUser>(u => u.Email.Equals(email));

            if (userWithEmail.Id != user.Id)
            {
                return(BasicResult.FailResult("Email already exists"));
            }

            var success = _repository.Update(user);

            if (!success)
            {
                return(BasicResult.FailResult("Database Error"));
            }

            return(BasicResult.SuccessResult());
        }