/**
  * get Array with Principal-Data from User-Object.
  *
  * @param UserInterface|GroupInterface $principalObject
  * @param bool                         $show_id
  *
  * @return array
  *
  * @throws Exception
  */
 private function getPrincipalArray($principalObject, $show_id = false)
 {
     if (!$principalObject instanceof UserInterface && !$principalObject instanceof GroupInterface) {
         throw new Exception('$principalObject must be of type UserInterface of GroupInterface');
     }
     $principal = array();
     if ($show_id) {
         $principal['id'] = $principalObject->getId();
     }
     if ($principalObject instanceof UserInterface) {
         $principal['uri'] = 'principals/' . $principalObject->getUsername();
     } else {
         $principal['uri'] = 'principals/' . $principalObject->getName();
     }
     // get all fields from $this->fieldMap, additional to 'uri' and 'id'
     foreach ($this->fieldMap as $key => $value) {
         if (!method_exists($principalObject, $value['getter'])) {
             continue;
         }
         $valueGetter = call_user_func(array($principalObject, $value['getter']));
         if ($valueGetter) {
             $principal[$key] = $valueGetter;
         }
     }
     return $principal;
 }
Exemplo n.º 2
0
 /**
  * @param UserInterface $user
  * @return UserDTO
  */
 public static function withEntity(UserInterface $user)
 {
     $dto = new UserDTO();
     $dto->setId($user->getId());
     $dto->setEmail($user->getEmail());
     $dto->setApiKey($user->getApiKey());
     return $dto;
 }
Exemplo n.º 3
0
 /**
  * @param UserInterface $user
  * @return bool|HttpToken
  */
 public function createRecoveryToken(UserInterface $user)
 {
     $currentDateTime = new \DateTime('now');
     $expiresAt = clone $currentDateTime;
     $expiresAt->add(new \DateInterval('PT' . self::LIFE_TIME_RECOVERY . 'S'));
     $refreshTo = clone $currentDateTime;
     $refreshTo->add(new \DateInterval('PT' . self::LIFE_TIME_RECOVERY . 'S'));
     $token = new HttpToken();
     $token->setUserId($user->getId())->setRefreshTo($refreshTo)->setExpiresAt($expiresAt)->setRecovery(true);
     $this->entityManager->persist($token);
     try {
         $this->entityManager->flush();
     } catch (ConstraintViolationException $e) {
         error_log($e->getMessage());
         return false;
     }
     return $token;
 }
Exemplo n.º 4
0
 public function getQueryPagination(UserInterface $entity, $sort, $direction)
 {
     $queryBuilder = $this->createQueryBuilder('u');
     $data = ['id' => $entity->getId(), 'username' => $entity->getUsername(), 'email' => $entity->getEmail(), 'enabled' => $entity->isEnabled()];
     if (!empty($data['id'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('u.id', ':id'))->setParameter('id', $data['id']);
     }
     if (!empty($data['username'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->like('u.username', ':username'))->setParameter('username', "%{$data['username']}%");
     }
     if (!empty($data['email'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->like('u.email', ':email'))->setParameter('email', "%{$data['email']}%");
     }
     if (!empty($data['enabled'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('u.enabled', ':enabled'))->setParameter('enabled', $data['enabled']);
     }
     $queryBuilder->orderBy('u.' . $sort, $direction);
     return $queryBuilder->getQuery();
 }
Exemplo n.º 5
0
 /**
  * Tells if the the given user is this user.
  *
  * Useful when not hydrating all fields.
  *
  * @param UserInterface $user
  * @return Boolean
  */
 public function isUser(UserInterface $user = null)
 {
     return null !== $user && $this->getId() === $user->getId();
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function reloadUser(UserInterface $user)
 {
     return $this->findUserBy(['id' => $user->getId()]);
 }
Exemplo n.º 7
0
 public function isMarked(UserInterface $user, Package $package)
 {
     return null !== $this->redis->zrank('usr:'******':fav', $package->getId());
 }
Exemplo n.º 8
0
 /**
  * @param UserInterface $user
  * @param BlameableEntityInterface $object
  *
  * @return bool
  */
 protected function isOwner(UserInterface $user, BlameableEntityInterface $object)
 {
     $creator = $object->getCreatedBy();
     return $creator instanceof UserInterface && $user->getId() === $creator->getId();
 }
Exemplo n.º 9
0
 /**
  * Tells if the the given user is this user.
  *
  * Useful when not hydrating all fields.
  *
  * @param UserInterface $user
  * @return Boolean
  */
 public function isUser(FOSUserInterface $user = null)
 {
     return $user instanceof self && $user->getId() == $this->getId();
 }
 function reloadUser(UserInterface $user)
 {
     $document = $this->documentHandler->get($this->collection, $user->getId());
     $this->fromDocument($user, $document);
 }
 /**
  * Add a user to a perimeter
  *
  * @param UserInterface              $user
  * @param BusinessPerimeterInterface $perimeter
  */
 public function addUserToPerimeter(UserInterface $user, BusinessPerimeterInterface $perimeter)
 {
     $this->perimeterManager->addUserToPerimeter($user->getId(), $perimeter->getId());
 }
Exemplo n.º 12
0
 protected function getRedirectionUrl(UserInterface $user)
 {
     return $this->container->get('router')->generate('user_profile', array('id' => $user->getId()));
 }
 /**
  * Generate the redirection url when the resetting is completed.
  *
  * @param \FOS\UserBundle\Model\UserInterface $user
  *
  * @return string
  */
 protected function getRedirectionUrl(UserInterface $user)
 {
     return $this->container->get('router')->generate('fos_user_profile_show', array("id" => $user->getId()));
 }