Пример #1
0
 /**
  * Stores user in the database
  * @param \src\User $user
  * @return bool
  * @throws \Exception
  */
 public function createUser(User $user)
 {
     if (!$user->isInputValid()) {
         throw new \InvalidArgumentException('Invalid user data');
     }
     $user->createPassword();
     $sql = "INSERT INTO users (firstname, lastname, email, password, salt) VALUES (:firstname, :lastname, :email, :password, :salt)";
     $statement = $this->db->prepare($sql);
     $statement->bindParam(':firstname', $user->firstName);
     $statement->bindParam(':lastname', $user->lastName);
     $statement->bindParam(':email', $user->email);
     $statement->bindParam(':password', $user->password);
     $statement->bindParam(':salt', $user->salt);
     if ($statement->execute()) {
         $user->userId = $this->db->lastInsertId();
         $this->sendActivationEmail($user);
         return true;
     } else {
         throw new \Exception('User wasn\'t saved:' . implode(':', $statement->errorInfo()));
     }
     return false;
 }
Пример #2
0
 public function testInvalidPassword()
 {
     $this->user->createPassword();
     $this->assertFalse($this->user->verifyPassword(null));
 }