예제 #1
0
 private function checkVoterRegistrationChanged(Person &$user)
 {
     if (null === $user->getVoterRegistration() || strlen($user->getVoterRegistration()) == 0) {
         return;
     }
     $aUser = $this->security->getToken()->getUser();
     if ($user->getVoterRegistration() != $this->voterRegistration) {
         if ($aUser->getNfgAccessToken()) {
             $this->nfg->setAccessToken($aUser->getNfgAccessToken());
             $this->nfg->setTituloEleitoral($user->getVoterRegistration());
             $nfgReturn1 = $this->nfg->consultaCadastro();
             if ($nfgReturn1['CodSitRetorno'] != 1) {
                 throw new NfgException($nfgReturn1['MsgRetorno']);
             }
             if (!isset($nfgReturn1['CodCpf'], $nfgReturn1['NomeConsumidor'], $nfgReturn1['EmailPrinc'])) {
                 throw new NfgException('nfg.missing.required.fields');
             }
         }
         $personRepo = $this->em->getRepository('PROCERGSLoginCidadaoCoreBundle:Person');
         $otherPerson = $personRepo->findOneBy(array('voterRegistration' => $user->getVoterRegistration()));
         if ($otherPerson) {
             if (isset($nfgReturn1)) {
                 if (isset($nfgReturn1['CodSitTitulo']) && $nfgReturn1['CodSitTitulo'] != 0) {
                     if ($nfgReturn1['CodSitTitulo'] == 1) {
                         $className = $this->em->getClassMetadata(get_class($aUser))->getName();
                         $uk = $this->em->getUnitOfWork();
                         $a = $uk->getOriginalEntityData($user);
                         $uk->detach($user);
                         $otherPerson->setVoterRegistration(null);
                         $this->em->persist($otherPerson);
                         $uk->registerManaged($user, array('id' => $user->getId()), $a);
                         $this->notificationsHelper->revokedVoterRegistrationNotification($otherPerson);
                         $aNfgProfile = $aUser->getNfgProfile();
                         $aNfgProfile->setVoterRegistrationSit($nfgReturn1['CodSitTitulo']);
                         $aNfgProfile->setVoterRegistration($user->getVoterRegistration());
                         $this->em->persist($aNfgProfile);
                     } else {
                         throw new LcValidationException('voterreg.already.used.but.nfg.mismatch');
                     }
                 } else {
                     throw new LcValidationException('voterreg.already.used.but.nfg.offer');
                 }
             } else {
                 throw new LcValidationException('voterreg.already.used');
             }
         } else {
             if (isset($nfgReturn1)) {
                 if (isset($nfgReturn1['CodSitTitulo']) && $nfgReturn1['CodSitTitulo'] != 0) {
                     if ($nfgReturn1['CodSitTitulo'] == 1) {
                         $aNfgProfile = $aUser->getNfgProfile();
                         $aNfgProfile->setVoterRegistrationSit($nfgReturn1['CodSitTitulo']);
                         $aNfgProfile->setVoterRegistration($user->getVoterRegistration());
                         $this->em->persist($aNfgProfile);
                     } else {
                         throw new LcValidationException('voterreg.nfg.fixit');
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private function checkCPFChanged(Person &$user)
 {
     if ($user->getCpf() !== $this->cpf) {
         if ($user->getCpf()) {
             $user->setCpfExpiration(null);
         } else {
             $cpfExpiryDate = new \DateTime($this->cpfEmptyTime);
             $user->setCpfExpiration($cpfExpiryDate);
         }
     }
 }
 private function addIdCard(Request $request, FormBuilderInterface $formBuilder, Person $person)
 {
     $state = $this->getStateFromRequest($request);
     $formData = $formBuilder->getData();
     foreach ($person->getIdCards() as $idCard) {
         if ($idCard->getState()->getId() === $state->getId()) {
             $formData->setIdCard($idCard);
             break;
         }
     }
     if (!$formData->getIdCard() instanceof IdCard) {
         $validationHandler = $this->getValidationHandler();
         $idCard = $validationHandler->instantiateIdCard($state);
         $idCard->setPerson($person);
         $formData->setIdCard($idCard);
     }
     $formBuilder->add('idcard', 'lc_idcard_form', array('label' => false));
 }
예제 #4
0
 public function isVoterRegistrationValid(Person $person, $voterRegistration = null)
 {
     if (is_null($voterRegistration)) {
         $voterRegistration = $person->getVoterRegistration();
     }
     if ($person->getNfgAccessToken()) {
         $this->setAccessToken($person->getNfgAccessToken());
         $this->setTituloEleitoral($voterRegistration);
         $nfgData = $this->consultaCadastro();
         // TODO: this shuldn't be here! It's NOT this method's job to validate
         // if the WebService's request was successful!
         if ($nfgData['CodSitRetorno'] != 1) {
             throw new NfgException($nfgData['MsgRetorno']);
         }
         // TODO: this shuldn't be here! It's NOT this method's job to validate
         // if the WebService's request was successful!
         if (!isset($nfgData['CodCpf'], $nfgData['NomeConsumidor'], $nfgData['EmailPrinc'])) {
             throw new NfgException('nfg.missing.required.fields');
         }
         if (array_key_exists('CodSitTitulo', $nfgData) && $nfgData['CodSitTitulo'] == 1) {
             return true;
         }
     } else {
         throw new MissingNfgAccessTokenException();
     }
     return false;
 }