/**
  * @param Configuration $configuration
  * @param ElectionInvitation $electionInvitation
  * @return bool
  */
 protected function sendElectionInvitation(Configuration $configuration, ElectionInvitation $electionInvitation)
 {
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     $electionCircular = $electionInvitation->getElectionCircular();
     $elector = $electionInvitation->getElector();
     $mail->setSubject($electionCircular->getSubject());
     $mail->setFrom([$configuration->getFromEmail() => $configuration->getFromName()]);
     if ($configuration->isDebug()) {
         $mail->setTo([$configuration->getTestEmail() => $elector->getFullName()]);
     } else {
         $mail->setTo([$elector->getEmail() => $elector->getFullName()]);
     }
     $mail->setBody($electionCircular->getRenderedBody($configuration, $electionInvitation));
     return $mail->send() === 1;
 }
Example #2
0
 /**
  * @param ElectionCircular $electionCircular
  * @param Elector $elector
  * @param Configuration $configuration
  * @return bool
  */
 public function sendElectionCircularToElector(ElectionCircular $electionCircular, Elector $elector, Configuration $configuration)
 {
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     $mail->setSubject($electionCircular->getSubject());
     $mail->setFrom([$configuration->getFromEmail() => $configuration->getFromName()]);
     $electionInvitation = new ElectionInvitation();
     $electionInvitation->setElector($elector);
     $electionInvitation->setElectionCircular($electionCircular);
     $electionInvitation->setSecret(GeneralUtility::getRandomHexString(mt_rand(180, 220)));
     $electionInvitationRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(ElectionInvitationRepository::class);
     $electionInvitationRepository->add($electionInvitation);
     $electionInvitationRepository->persistAll();
     if ($configuration->isDebug()) {
         $mail->setTo([$configuration->getTestEmail() => $elector->getFullName()]);
     } else {
         $mail->setTo([$elector->getEmail() => $elector->getFullName()]);
     }
     $mail->setBody($electionCircular->getRenderedBody($configuration, $electionInvitation));
     return $mail->send() === 1;
 }
 /**
  * @param ElectionInvitation $electionInvitation
  * @param string $hmac
  * @return string
  */
 public function voteAction(ElectionInvitation $electionInvitation = null, $hmac = '')
 {
     if (null !== $electionInvitation && '' !== $hmac) {
         $saltedEmail = $electionInvitation->getSecret() . $electionInvitation->getElector()->getEmail();
         if ($this->hashService->validateHmac($saltedEmail, $hmac)) {
             if ($electionInvitation->isVoted()) {
                 $this->addFlashMessage(LocalizationUtility::translate('controller.fe.election.vote.already_voted', 'election'), LocalizationUtility::translate('controller.fe.election.vote.request_failed', 'election'), AbstractMessage::ERROR);
                 $this->redirect(FeDashboardController::ACTION_INDEX, FeDashboardController::CONTROLLER_NAME);
             } elseif ($electionInvitation->getElectionEndDateAsTimestamp() < time()) {
                 $this->addFlashMessage(LocalizationUtility::translate('controller.fe.election.vote.election_finished', 'election'), LocalizationUtility::translate('controller.fe.election.vote.request_failed', 'election'), AbstractMessage::ERROR);
                 $this->redirect(FeDashboardController::ACTION_INDEX, FeDashboardController::CONTROLLER_NAME);
             } else {
                 $this->view->assign('electionInvitation', $electionInvitation);
                 $this->view->assign('electionVoting', new ElectionVoting());
             }
         } else {
             $this->addFlashMessage(LocalizationUtility::translate('controller.fe.election.vote.hmac_invalid', 'election'), LocalizationUtility::translate('controller.fe.election.vote.request_failed', 'election'), AbstractMessage::ERROR);
             $this->redirect(FeDashboardController::ACTION_INDEX, FeDashboardController::CONTROLLER_NAME);
         }
     } else {
         $this->addFlashMessage(LocalizationUtility::translate('controller.fe.election.vote.no_election_or_hmac', 'election'), LocalizationUtility::translate('controller.fe.election.vote.request_failed', 'election'), AbstractMessage::ERROR);
         $this->redirect(FeDashboardController::ACTION_INDEX, FeDashboardController::CONTROLLER_NAME);
     }
 }
Example #4
0
 /**
  * @param Configuration $configuration
  * @param ElectionInvitation $electionInvitation
  * @return string
  * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
  * @throws \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException
  */
 protected function getLink(Configuration $configuration, ElectionInvitation $electionInvitation)
 {
     $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
     $hashService = $objectManager->get(HashService::class);
     if (!isset($GLOBALS['TT'])) {
         $GLOBALS['TT'] = GeneralUtility::makeInstance(TimeTracker::class);
     }
     if (!isset($GLOBALS['TSFE'])) {
         $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], $configuration->getPluginPid(), 0);
         $GLOBALS['TSFE']->config = ['config' => []];
         $GLOBALS['TSFE']->initFEuser();
         $GLOBALS['TSFE']->fetch_the_id();
         $GLOBALS['TSFE']->initTemplate();
     }
     $uriBuilder = $objectManager->get(UriBuilder::class);
     $uriBuilder->setTargetPageUid($configuration->getPluginPid());
     $uriBuilder->setCreateAbsoluteUri(true);
     $uriBuilder->setUseCacheHash(false);
     $uriBuilder->uriFor(FeElectionController::ACTION_VOTE, ['electionInvitation' => $electionInvitation, 'hmac' => $hashService->generateHmac($electionInvitation->getSecret() . $electionInvitation->getElector()->getEmail())], FeElectionController::CONTROLLER_NAME, 'election', 'pi1');
     return $uriBuilder->buildFrontendUri();
 }