/// <summary>
        /// Executes the query
        /// </summary>
        /// <returns></returns>
        public virtual User Execute()
        {
            // Make the supplised username lower case and trimmed
            _email = _email.Trim().ToLower();

            // Return the user with the matching username
            var user = _unitOfWork.Users
                       .Fetch()
                       .Where(x => x.Email == _email)
                       .SingleOrDefault();

            // If no user was found, return null
            if (user == null)
            {
                return(null);
            }

            // Check if the password is correct
            if (PasswordUtils.CheckPasswordHash(_email, _password, user.Password))
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
        public void Execute_Returns_New_Password_For_User()
        {
            // Setup
            InitializeTestEntities();

            // Act
            string newPass = new ResetUserPasswordCommand(_unitOfWork, _mock.Object).WithUserEmail(_user.Email).Execute();
            User   user    = _unitOfWork.Users.Fetch().Single();

            // Verify
            Assert.IsTrue(PasswordUtils.CheckPasswordHash(user.Email, newPass, user.Password), "New password does not validate");
        }
示例#3
0
        public void Incorrect_User_Credentials_Fails_Password_Check()
        {
            // Setup
            string username = "******";
            string password = "******";
            string hash     = "$2a$15$qPHP3aj9z3j/6f/4BGwuUeuIgWYqidQ/OxrXEayXVoc1RC5s9rLse";

            // Act
            bool result = PasswordUtils.CheckPasswordHash(username, password, hash);

            // Verify
            Assert.IsFalse(result, "Password check passed but should have failed");
        }
示例#4
0
        public void Execute_Returns_Created_User()
        {
            // Setup

            // Act
            User user = new CreateUserCommand(_serviceFactory.Object).Execute(new CreateUserCommandParams
            {
                Email             = "*****@*****.**",
                PlainTextPassword = "******"
            });

            // Verify
            Assert.IsNotNull(user, "Execute returned a null user");
            Assert.AreEqual("*****@*****.**", user.Email, "User's email was incorrect");
            Assert.IsTrue(PasswordUtils.CheckPasswordHash(user.Email, "password", user.Password), "User's password could not be validated");
        }
示例#5
0
        public void Can_Create_New_User()
        {
            // Setup

            // Act
            new CreateUserCommand(_serviceFactory.Object).Execute(new CreateUserCommandParams
            {
                Email             = "*****@*****.**",
                PlainTextPassword = "******"
            });

            // Verify
            User user = _unitOfWork.Users.Fetch().SingleOrDefault();

            Assert.IsNotNull(user, "No user was created");
            Assert.AreEqual("*****@*****.**", user.Email, "User's email was incorrect");
            Assert.IsTrue(PasswordUtils.CheckPasswordHash(user.Email, "password", user.Password), "User's password could not be validated");
        }
        public void Execute_Returns_Edited_User()
        {
            // Setup
            InitializeTestEntities();

            // Act
            User result = new EditUserCommand(_unitOfWork).WithUserId(_user.Id)
                          .SetLastVisitedJobSearchId(_search.Id)
                          .WithExistingPassword(_oldPassword)
                          .Execute();

            // Verify
            Assert.IsNotNull(result, "No user was found in the repository");
            Assert.AreEqual(_user, result, "User was incorrect");
            Assert.AreEqual(_startingEmail, result.Email, "User's email was incorrect");
            Assert.IsTrue(PasswordUtils.CheckPasswordHash(_startingEmail, _oldPassword, result.Password), "User's password was incorrect");
            Assert.AreEqual(_search.Id, result.LastVisitedJobSearchId, "User's last visited jobsearch id was incorrect");
        }
        public void LastVisitedJobSearchId_Is_Not_Changed_When_Not_Specified()
        {
            // Setup
            InitializeTestEntities();

            // Act
            new EditUserCommand(_unitOfWork).WithUserId(_user.Id)
            .SetPassword("new password")
            .WithExistingPassword(_oldPassword)
            .Execute();
            User result = _unitOfWork.Users.Fetch().SingleOrDefault();

            // Verify
            Assert.IsNotNull(result, "No user was found in the repository");
            Assert.AreEqual(_user, result, "User was incorrect");
            Assert.AreEqual(_startingEmail, result.Email, "User's email was incorrect");
            Assert.IsTrue(PasswordUtils.CheckPasswordHash(result.Email, "new password", result.Password), "User's password was incorrect");
            Assert.AreEqual(_search.Id, result.LastVisitedJobSearchId, "User's last visited jobsearch id was incorrect");
        }