/**
  * @param int $limit
  * @param PersonInterface $impersonator
  * @return \Doctrine\ORM\QueryBuilder
  */
 private function getImpersonatonsWithoutReportsQuery($limit = null, PersonInterface $impersonator = null)
 {
     $query = $this->createQueryBuilder('l')->leftJoin('LoginCidadaoCoreBundle:ImpersonationReport', 'r', 'WITH', 'r.actionLog = l')->where('r.id IS NULL')->andWhere('l.actionType = :type')->setParameter('type', ActionLog::TYPE_IMPERSONATE);
     if ($impersonator instanceof PersonInterface) {
         $query->andWhere('l.clientId = :impersonatorId')->setParameter('impersonatorId', $impersonator->getId());
     }
     if ($limit > 0) {
         $query->setMaxResults($limit);
     }
     return $query;
 }
 public function getTargetPersonLevel(PersonInterface $person)
 {
     $roles = $person->getRoles();
     $level = 0;
     foreach ($this->getRoleMapping() as $role => $lvl) {
         if (in_array($role, $roles)) {
             $level = $lvl;
             break;
         }
     }
     return $level;
 }
 /**
  * @param PersonInterface $subject
  * @param ClientMetadata|null $metadata
  * @return string
  */
 public function getSubjectIdentifier(PersonInterface $subject, ClientMetadata $metadata = null)
 {
     $id = $subject->getId();
     if ($metadata === null || $metadata->getSubjectType() !== 'pairwise') {
         return $id;
     }
     if ($metadata->getSubjectType() === 'pairwise') {
         $sectorIdentifier = $metadata->getSectorIdentifier();
         $salt = $this->pairwiseSubjectIdSalt;
         $pairwise = hash('sha256', $sectorIdentifier . $id . $salt);
         return $pairwise;
     }
 }
 public static function populateCountryStateCity(PersonInterface $person, FormInterface $form)
 {
     $country = $person->getCountry();
     $state = $person->getState();
     $city = $person->getCity();
     $countryName = '';
     if ($country) {
         $countryName = $country->getName();
     }
     $form->add('country', 'text', array('required' => true, 'mapped' => false, 'read_only' => true, 'data' => $countryName));
     $stateName = '';
     if ($state) {
         $stateName = $state->getName();
     }
     $form->add('state', 'text', array('required' => true, 'read_only' => 'true', 'mapped' => false, 'read_only' => true, 'data' => $stateName));
     $cityName = '';
     if ($city) {
         $cityName = $city->getName();
     }
     $form->add('city', 'text', array('required' => true, 'read_only' => 'true', 'mapped' => false, 'read_only' => true, 'data' => $cityName));
     return $form;
 }
 public function registerImpersonate(Request $request, PersonInterface $person, PersonInterface $impersonator, array $controllerAction, $isImpersonating)
 {
     $auditUsername = $this->auditConfig->getCurrentUsername();
     if ($isImpersonating) {
         $actionType = ActionLog::TYPE_IMPERSONATE;
     } else {
         $actionType = ActionLog::TYPE_DEIMPERSONATE;
     }
     $log = $this->initLog($request, $actionType, $controllerAction, $auditUsername);
     $log->setUserId($person->getId());
     $log->setClientId($impersonator->getId());
     $this->em->persist($log);
     $this->em->flush($log);
 }
 /**
  * @param PersonInterface $user
  * @param string $scope
  * @return bool
  */
 private function checkScope(PersonInterface $user, $scope)
 {
     // 'id_cards', 'addresses'
     switch ($scope) {
         case 'name':
         case 'full_name':
         case 'surname':
             $value = $user->getFullName();
             return $value && strlen($value) > 0 && strlen($user->getSurname()) > 0;
             break;
         case 'mobile':
         case 'phone_number':
             $value = $user->getMobile();
             break;
         case 'country':
             return $user->getCountry() instanceof Country;
         case 'state':
             return $user->getState() instanceof State;
         case 'city':
             return $user->getCity() instanceof City;
         case 'birthdate':
             return $user->getBirthdate() instanceof \DateTime;
         case 'email':
         case 'email_verified':
             return $user->getEmailConfirmedAt() instanceof \DateTime;
         case 'cpf':
             $cpf = $user->getCpf();
             return $cpf && CPFValidator::isCPFValid($cpf);
         default:
             return true;
     }
     return $value && strlen($value) > 0;
 }
 protected function removeBackupCodes(EntityManager $em, PersonInterface $person)
 {
     $backupCodes = $person->getBackupCodes();
     foreach ($backupCodes as $backupCode) {
         $em->remove($backupCode);
     }
 }
 private function resendEmailConfirmation(PersonInterface $person)
 {
     $mailer = $this->get('fos_user.mailer');
     if (is_null($person->getEmailConfirmedAt())) {
         if (is_null($person->getConfirmationToken())) {
             $tokenGenerator = new TokenGenerator();
             $person->setConfirmationToken($tokenGenerator->generateToken());
             $userManager = $this->get('fos_user.user_manager');
             $userManager->updateUser($person);
         }
         $mailer->sendConfirmationEmailMessage($person);
         $this->flashEmailSent();
         return $this->redirectToRoute('task_confirm_email');
     }
 }