public function testGetSetHasEmail() { $this->assertFalse($this->criteria->hasEmail()); $this->criteria->setEmail('*****@*****.**'); $this->assertTrue($this->criteria->hasEmail()); $this->assertEquals('*****@*****.**', $this->criteria->getEmail()); }
/** * @param string $email * @param string $password * @return int * @throws UserException */ function authenticate($email, $password) { $criteria = new UserCriteria(); $criteria->setEmail($email); $user = $this->getUserRepository()->findByCriteria($criteria); if (empty($user)) { throw new UserException(UserException::USER_NOT_FOUND); } /** @var User $user */ $user = $user[0]; switch ($user->getState()->getValue()) { case State::STATE_UNACTIVATED: throw new UserException(UserException::USER_UNACTIVATED); break; case State::STATE_DISABLED: case State::STATE_SUSPENDED: throw new UserException(UserException::USER_DISABLED); break; case State::STATE_BANNED: throw new UserException(UserException::USER_BANNED); break; } $bcrypt = new Bcrypt(); $bcrypt->setCost(14); if (!$bcrypt->verify($password, $user->getPassword())) { throw new UserException(UserException::WRONG_PASSWORD); } return $user->getID(); }
public function testFindByCriteria() { $user = $this->svc->createFromArray($this->getUserArray('testFindByCriteria')); $this->svc->saveUser($user); $criteria = new UserCriteria(); $criteria->setEmail('*****@*****.**')->setRegistrationDate('1970-01-01')->setLastLoginDate('1970-01-01')->setState((string) State::STATE_UNACTIVATED); $user = $this->svc->findByCriteria($criteria)[0]; $this->assertInstanceOf('Del\\Entity\\User', $user); $this->svc->deleteUser($user, true); }