Example #1
0
 private function checkAllTokens(UserInterface $user, $tokenHash)
 {
     $now = new \DateTime();
     $tokensToRemove = array();
     $throwExpirationDateException = false;
     /** @var Token $token */
     foreach ($user->getTokens() as $key => $token) {
         if ($token->getExpirationDate() < $now) {
             $tokensToRemove[$key] = $token;
         }
         if ($token->getHash() == $tokenHash) {
             if ($token->getExpirationDate() < $now) {
                 $throwExpirationDateException = true;
             }
         }
     }
     if (!empty($tokensToRemove)) {
         foreach ($tokensToRemove as $key => $token) {
             $user->getTokens()->remove($key);
             $this->repositoryService->remove($token);
         }
     }
     if ($throwExpirationDateException) {
         throw new TokenExpirationDateExpiredException();
     }
 }
 /**
  * @param User $user
  * @return \Doctrine\Common\Collections\Collection|null
  */
 protected function getEmployees(User $user)
 {
     $organization = $user->getOrganization();
     if (!$organization) {
         return;
     }
     $organization = $organization->getOrganization();
     if (!$organization) {
         return;
     }
     return $organization->getEmployees();
 }
 public function generate(UserInterface $user, $daysToLive = 1, $storeUser = true)
 {
     $tokenHash = Rand::getString(64, $this->charList);
     $dateStr = sprintf('+ %d day', $daysToLive);
     $expirationDate = new \Datetime($dateStr);
     /* @todo We should consider using the Prototype Design Pattern here. */
     $token = new Token();
     $token->setHash($tokenHash)->setExpirationDate($expirationDate);
     $user->getTokens()->add($token);
     if ($storeUser) {
         $this->repositoryService->store($user);
     }
     return $tokenHash;
 }
Example #4
0
 /**
  * for people
  * following parameter are relevant
  * by     => 'all', 'me', 'guest'
  * status => Status::CREATED, 'all'
  * user   => User::ROLE_RECRUITER, User::ROLE_ADMIN, User::ROLE_USER
  *
  * @param $params
  * @param $queryBuilder
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     $this->value = $params->toArray();
     $this->user = $this->auth->getUser();
     $isRecruiter = $this->user->getRole() == User::ROLE_RECRUITER || $this->acl->inheritsRole($this->user, User::ROLE_RECRUITER);
     if ($isRecruiter && (!isset($this->value['by']) || $this->value['by'] != 'guest')) {
         /*
          * a recruiter can see his jobs and jobs from users who gave permissions to do so
          */
         if (isset($this->value['params']['by']) && 'me' == $this->value['params']['by']) {
             $queryBuilder->field('user')->equals($this->user->id);
         } else {
             $queryBuilder->field('permissions.view')->equals($this->user->id);
         }
         if (isset($this->value['params']['status']) && !empty($this->value['params']['status']) && $this->value['params']['status'] != 'all') {
             $queryBuilder->field('status.name')->equals((string) $this->value['params']['status']);
         }
     } else {
         /*
          * an applicants or guests can see all active jobs
          */
         $queryBuilder->field('status.name')->equals(Status::ACTIVE);
     }
     /*
      * search jobs by keywords
      */
     if (isset($this->value['params']['search']) && !empty($this->value['params']['search'])) {
         $search = strtolower($this->value['params']['search']);
         $searchPatterns = array();
         foreach (explode(' ', $search) as $searchItem) {
             $searchPatterns[] = new \MongoRegex('/^' . $searchItem . '/');
         }
         $queryBuilder->field('keywords')->all($searchPatterns);
     }
     if (isset($this->value['location'])) {
         $loc = $this->value['location'];
         $queryBuilder->field('locations.coordinates')->near($loc->getCoordinates())->maxDistance($this->value['d'] * 1000);
     }
     if (isset($this->value['sort'])) {
         foreach (explode(",", $this->value['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }
Example #5
0
 /**
  * for people
  * following parameter are relevant
  * by     => 'all', 'me', 'guest'
  * status => Status::CREATED, 'all'
  * user   => User::ROLE_RECRUITER, User::ROLE_ADMIN, User::ROLE_USER
  *
  * @param $params Parameters
  * @param $queryBuilder \Doctrine\ODM\MongoDB\Query\Builder
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     $this->value = $params;
     /*
      * search jobs by keywords
      */
     if (isset($params['search']) && !empty($params['search'])) {
         $search = strtolower($params['search']);
         $expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
         $queryBuilder->field(null)->equals($expression->getQuery());
     }
     if (isset($this->value['location']->coordinates)) {
         $coordinates = $this->value['location']->coordinates->getCoordinates();
         $queryBuilder->field('locations.coordinates')->geoWithinCenter($coordinates[0], $coordinates[1], (double) $this->value['d'] / 100);
     }
     if (isset($params['channel']) && !empty($params['channel']) && $params['channel'] != "default") {
         $queryBuilder->field('portals')->equals($params['channel']);
     }
     $this->user = $this->auth->getUser();
     $isRecruiter = $this->user->getRole() == User::ROLE_RECRUITER || $this->acl->inheritsRole($this->user, User::ROLE_RECRUITER);
     if ($isRecruiter && (!isset($this->value['by']) || $this->value['by'] != 'guest')) {
         /*
          * a recruiter can see his jobs and jobs from users who gave permissions to do so
          */
         if (isset($params['by']) && 'me' == $params['by']) {
             $queryBuilder->field('user')->equals($this->user->id);
         } else {
             $queryBuilder->field('permissions.view')->equals($this->user->id);
         }
         if (isset($params['status']) && !empty($params['status']) && $params['status'] != 'all') {
             $queryBuilder->field('status.name')->equals((string) $params['status']);
         }
     } else {
         /*
          * an applicants or guests can see all active jobs
          */
         $queryBuilder->field('status.name')->equals(Status::ACTIVE);
     }
     if (isset($this->value['sort'])) {
         foreach (explode(",", $this->value['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }
Example #6
0
 /**
  * @param Request $request
  * @param User $user
  * @return string
  */
 public function detectLanguage(Request $request, User $user = null)
 {
     if (isset($user)) {
         $settings = $user->getSettings('Core');
         if (isset($settings->localization) && isset($settings->localization->language) && $settings->localization->language != '') {
             // return language by user's settings
             return $settings->localization->language;
         }
     }
     $headers = $request->getHeaders();
     if ($headers->has('Accept-Language')) {
         $locales = $headers->get('Accept-Language')->getPrioritized();
         foreach ($locales as $locale) {
             $language = $locale->type;
             if (isset($this->supportedLanguages[$language])) {
                 // return language by browser's accept language
                 return $language;
             }
         }
     }
     // no match, therefore return default language
     return $this->defaultLanguage;
 }
Example #7
0
 /**
  * Gets/Generates the resource id.
  *
  * @param string|UserInterface|PermissionsResourceInterface $resource
  *
  * @return string
  */
 protected function getResourceId($resource)
 {
     if ($resource instanceof PermissionsResourceInterface) {
         return $resource->getPermissionsResourceId();
     }
     if ($resource instanceof UserInterface) {
         return 'user:'******'user:' . $resource;
 }
Example #8
0
 /**
  * @see \Auth\Dependency\ListInterface::getEntities()
  */
 public function getEntities(User $user)
 {
     return $this->repository->getUserOrganizations($user->getId());
 }
Example #9
0
 /**
  * @param string $query
  * @param UserInterface    $user
  * @return array
  */
 public function getTypeAheadResults($query, $user)
 {
     $organizationNames = array();
     $organizationNameQb = $this->getDocumentManager()->createQueryBuilder('Organizations\\Entity\\OrganizationName');
     $organizationNameQb->hydrate(false)->select(array('id', 'name'))->field('name')->equals(new \MongoRegex('/' . $query . '/i'))->sort('name')->limit(5);
     $organizationNameResults = $organizationNameQb->getQuery()->execute();
     foreach ($organizationNameResults as $id => $item) {
         $organizationNames[$id] = $item;
     }
     $organizations = array();
     $userOrg = $user->getOrganization();
     $qb = $this->createQueryBuilder();
     $qb->hydrate(false)->select(array('contact.city', 'contact.street', 'contact.houseNumber', 'organizationName'))->limit(5)->addAnd($qb->expr()->field('permissions.view')->equals($user->getId())->field('organizationName')->in(array_keys($organizationNames)));
     if ($userOrg->hasAssociation()) {
         $qb->addAnd($qb->expr()->addOr($qb->expr()->field('parent')->equals($userOrg->getId()))->addOr($qb->expr()->field('_id')->equals($userOrg->getId())));
     }
     $result = $qb->getQuery()->execute();
     foreach ($result as $id => $item) {
         $organizations[$id] = $item;
         $organizationNameId = (string) $organizations[$id]['organizationName'];
         $organizations[$id]['organizationName'] = $organizationNames[$organizationNameId];
     }
     return $organizations;
 }
Example #10
0
 /**
  * Returns true, if a User is an employee of the organization
  *
  * @param UserInterface $user
  *
  * @return bool
  */
 public function isEmployee(UserInterface $user)
 {
     return $this->refs && in_array($user->getId(), $this->refs->getEmployeeIds());
 }
Example #11
0
 /**
  * Gets an employee by User or ID.
  *
  * @param UserInterface|string $userOrId
  *
  * @return mixed|null
  */
 public function getEmployee($userOrId)
 {
     $employees = $this->getEmployees();
     $userId = $userOrId instanceof \Auth\Entity\UserInterface ? $userOrId->getId() : $userOrId;
     foreach ($employees as $employee) {
         if ($employee->getUser()->getId() == $userId) {
             return $employee;
         }
     }
     return null;
 }
Example #12
0
 /**
  * @param UserInterface $user
  * @param array $options
  * @throws UserDeactivatedException
  * @return null | UserInterface
  */
 protected function assertEntity(UserInterface $user = null, array $options)
 {
     if (isset($user) && (!isset($options['allowDeactivated']) || !$options['allowDeactivated']) && !$user->isActive()) {
         throw new UserDeactivatedException(sprintf('User with ID %s is not active', $user->getId()));
     }
     return $user;
 }