public function testGetSetHasState() { $this->assertFalse($this->criteria->hasState()); $this->criteria->setState(1); $this->assertTrue($this->criteria->hasState()); $this->assertEquals(1, $this->criteria->getState()); }
/** * @param UserCriteria $criteria * @return array */ public function findByCriteria(UserCriteria $criteria) { $qb = $this->createQueryBuilder('u'); if ($criteria->hasId()) { $qb->where('u.id = :id'); $qb->setParameter('id', $criteria->getId()); $criteria->setLimit(1); } if ($criteria->hasEmail()) { $qb->where('u.email = :email'); $qb->setParameter('email', $criteria->getEmail()); $criteria->setLimit(1); } if ($criteria->hasState()) { $qb->andWhere('u.state = :state'); $qb->setParameter('state', $criteria->getState()); } if ($criteria->hasRegistrationDate()) { $qb->andWhere('u.registrationDate = :regdate'); $qb->setParameter('regdate', $criteria->getRegistrationDate()); } if ($criteria->hasLastLoginDate()) { $qb->andWhere('u.lastLoginDate = :lastlogin'); $qb->setParameter('lastlogin', $criteria->getLastLoginDate()); } $criteria->hasOrder() ? $qb->addOrderBy('u.' . $criteria->getOrder(), $criteria->getOrderDirection()) : null; $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null; $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null; $query = $qb->getQuery(); return $query->getResult(); }
/** * @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); }