/**
  * Authenticates the given user. If successful, an instance
  * of the user is returned.
  *
  * @param User $user The user to authenticate
  * @throws InvalidLoginDataException Thrown if the user's credentials are not valid
  */
 public function authenticate(User $user)
 {
     $result = PartKeepr::getEM()->getRepository("PartKeepr\\User\\User")->findOneBy(array("username" => $user->getUsername(), "password" => $user->getHashedPassword()));
     if ($result == null) {
         throw new InvalidLoginDataException();
     } else {
         return $result;
     }
 }
Exemple #2
0
 /**
  * Tests the deserialize method
  */
 public function testDeserialize()
 {
     $username = "******";
     $password = "******";
     $hashedPassword = md5($password);
     $input = array("username" => $username, "password" => $password);
     $user = new User();
     $user->deserialize($input);
     $this->assertEquals($username, $user->getUsername());
     $this->assertEquals($hashedPassword, $user->getHashedPassword());
 }