Пример #1
0
 /**
  * Returns the hmac for the given registration in order to cancel the registration
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
  *
  * @return array
  */
 public function render($registration)
 {
     $result = '';
     if ($registration) {
         $result = $this->hashService->generateHmac('reg-' . $registration->getUid());
     }
     return $result;
 }
 /**
  * Start password reset
  *
  * @param string $username Username of a user
  * @return void
  *
  * @validate $username NotEmpty
  */
 public function startPasswordResetAction($username)
 {
     $user = $this->frontendUserRepository->findOneByUsername($username);
     // Forbid password reset if there is no password or password property,
     // e.g. if the user has not completed a special registration process
     // or is supposed to authenticate in some other way
     $password = ObjectAccess::getPropertyPath($user, 'password');
     if ($password === NULL) {
         $this->logger->error('Failed to initiate password reset for user "' . $username . '": no password present');
         $this->addLocalizedFlashMessage('resetPassword.failed.nopassword', NULL, FlashMessage::ERROR);
         $this->redirect('showPasswordResetForm');
     }
     $hash = md5(GeneralUtility::generateRandomBytes(64));
     $token = array('uid' => $user->getUid(), 'hmac' => $this->hashService->generateHmac($password));
     $tokenLifetime = $this->getSettingValue('passwordReset.token.lifetime');
     // Remove possibly existing reset tokens and store new one
     $this->tokenCache->flushByTag($user->getUid());
     $this->tokenCache->set($hash, $token, array($user->getUid()), $tokenLifetime);
     $expiryDate = new \DateTime(sprintf('now + %d seconds', $tokenLifetime));
     $hashUri = $this->uriBuilder->setTargetPageUid($this->getSettingValue('passwordReset.page'))->setUseCacheHash(FALSE)->setCreateAbsoluteUri(TRUE)->uriFor('showPasswordResetForm', array('hash' => $hash));
     /** @var \PAGEmachine\Hairu\Domain\DTO\PasswordResetRequestTransferObject $passwordResetRequestTransferObject */
     $passwordResetRequestTransferObject = GeneralUtility::makeInstance('PAGEmachine\\Hairu\\Domain\\DTO\\PasswordResetRequestTransferObject');
     $passwordResetRequestTransferObject->setUser($user);
     $passwordResetRequestTransferObject->setHash($hash);
     $passwordResetRequestTransferObject->setHashUri($hashUri);
     $passwordResetRequestTransferObject->setExpiryDate($expiryDate);
     $actionVariables = array('user' => $user, 'hash' => $hash, 'hashUri' => $hashUri, 'expiryDate' => $expiryDate);
     $this->view->assignMultiple($actionVariables);
     /** @var \TYPO3\CMS\Core\Mail\MailMessage $message */
     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setFrom($this->getSettingValue('passwordReset.mail.from'))->setTo($user->getEmail())->setSubject($this->getSettingValue('passwordReset.mail.subject'));
     $this->request->setFormat('txt');
     $message->setBody($this->view->render('passwordResetMail'), 'text/plain');
     $this->request->setFormat('html');
     $message->addPart($this->view->render('passwordResetMail'), 'text/html');
     $mailSent = FALSE;
     $passwordResetRequestTransferObject->setMessage($message);
     $this->emitBeforePasswordResetMailSendSignal($passwordResetRequestTransferObject);
     try {
         $mailSent = $message->send();
     } catch (\Swift_SwiftException $e) {
         $this->logger->error($e->getMessage());
     }
     if ($mailSent) {
         $this->addLocalizedFlashMessage('resetPassword.started', NULL, FlashMessage::INFO);
     } else {
         $this->addLocalizedFlashMessage('resetPassword.failed.sending', NULL, FlashMessage::ERROR);
     }
     $this->redirect('showPasswordResetForm');
 }
 /**
  * Returns the rendered HTML for the given template
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
  * @param string $template Template
  * @param array $settings Settings
  *
  * @return string
  */
 protected function getNotificationBody($event, $registration, $template, $settings)
 {
     /** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */
     $emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
     $emailView->setFormat('html');
     $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
     $templateRootPath = GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['plugin.']['tx_sfeventmgt.']['view.']['templateRootPath']);
     $layoutRootPath = GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['plugin.']['tx_sfeventmgt.']['view.']['layoutRootPath']);
     $emailView->setLayoutRootPath($layoutRootPath);
     $emailView->setTemplatePathAndFilename($templateRootPath . $template);
     $emailView->assignMultiple(array('event' => $event, 'registration' => $registration, 'settings' => $settings, 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()), 'reghmac' => $this->hashService->appendHmac((string) $registration->getUid())));
     $emailBody = $emailView->render();
     return $emailBody;
 }
 /**
  * Returns the rendered HTML for the given template
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
  * @param string $template Template
  * @param array $settings Settings
  *
  * @return string
  */
 protected function getNotificationBody($event, $registration, $template, $settings)
 {
     /** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */
     $emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
     $emailView->setFormat('html');
     $layoutRootPaths = $this->fluidStandaloneService->getTemplateFolders('layout');
     $partialRootPaths = $this->fluidStandaloneService->getTemplateFolders('partial');
     if (TYPO3_MODE === 'BE' && $registration->getLanguage() !== '') {
         // Temporary set Language of current BE user to given language
         $GLOBALS['BE_USER']->uc['lang'] = $registration->getLanguage();
         $emailView->getRequest()->setControllerExtensionName('SfEventMgt');
     }
     $emailView->setLayoutRootPaths($layoutRootPaths);
     $emailView->setPartialRootPaths($partialRootPaths);
     $emailView->setTemplatePathAndFilename($this->fluidStandaloneService->getTemplatePath($template));
     $emailView->assignMultiple(['event' => $event, 'registration' => $registration, 'settings' => $settings, 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()), 'reghmac' => $this->hashService->appendHmac((string) $registration->getUid())]);
     $emailBody = $emailView->render();
     return $emailBody;
 }
Пример #5
0
 /**
  * Show action
  *
  * @return void
  */
 public function showAction()
 {
     $uniqueid = strtolower(substr(base64_encode(sha1(microtime())), 0, 9));
     $stringToHash = $GLOBALS['TSFE']->id . $this->settings['category'] . $this->settings['startingPoint'] . $this->settings['displayMode'];
     $hmac = $this->hashService->generateHmac($stringToHash);
     $this->view->assign('pid', $GLOBALS['TSFE']->id);
     $this->view->assign('lang', $GLOBALS['TSFE']->sys_language_uid);
     $this->view->assign('categories', $this->settings['category']);
     $this->view->assign('startingPoint', $this->settings['startingPoint']);
     $this->view->assign('displayMode', $this->settings['displayMode']);
     $this->view->assign('typeNum', $this->settings['ajaxPageTypeNum']);
     $this->view->assign('uniqueid', $uniqueid);
     $this->view->assign('hmac', $hmac);
     /* Find all banners and add additional CSS */
     $banners = $this->bannerRepository->findAll();
     $cssFile = $this->bannerService->getAdditionalCssFile($banners);
     if ($cssFile != '') {
         $GLOBALS['TSFE']->getPageRenderer()->addCssFile($cssFile, 'stylesheet', 'all', '', TRUE);
     }
 }
Пример #6
0
 /**
  * Saves the registration
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
  * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator
  *
  * @return void
  */
 public function saveRegistrationAction(Registration $registration, Event $event)
 {
     $autoConfirmation = (bool) $this->settings['registration']['autoConfirmation'];
     $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
     $success = $this->checkRegistrationSuccess($event, $registration, $result);
     // Save registration if no errors
     if ($success) {
         $linkValidity = (int) $this->settings['confirmation']['linkValidity'];
         if ($linkValidity === 0) {
             // Use 3600 seconds as default value if not set
             $linkValidity = 3600;
         }
         $confirmationUntil = new \DateTime();
         $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
         $registration->setEvent($event);
         $registration->setPid($event->getPid());
         $registration->setConfirmationUntil($confirmationUntil);
         $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid);
         $this->registrationRepository->add($registration);
         // Persist registration, so we have an UID
         $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
         // Send notifications to user and admin if confirmation link should be sent
         if (!$autoConfirmation) {
             $this->notificationService->sendUserMessage($event, $registration, $this->settings, MessageType::REGISTRATION_NEW);
             $this->notificationService->sendAdminMessage($event, $registration, $this->settings, MessageType::REGISTRATION_NEW);
         }
         // Create given amount of registrations if necessary
         if ($registration->getAmountOfRegistrations() > 1) {
             $this->registrationService->createDependingRegistrations($registration);
         }
         // Clear cache for configured pages
         $this->utilityService->clearCacheForConfiguredUids($this->settings);
     }
     if ($autoConfirmation && $success) {
         $this->redirect('confirmRegistration', NULL, NULL, array('reguid' => $registration->getUid(), 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())));
     } else {
         $this->redirect('saveRegistrationResult', NULL, NULL, array('result' => $result));
     }
 }
Пример #7
0
 /**
  * @test
  */
 public function generatedHmacCanBeValidatedAgain()
 {
     $string = 'asdf';
     $hash = $this->hashService->generateHmac($string);
     $this->assertTrue($this->hashService->validateHmac($string, $hash));
 }
Пример #8
0
 /**
  * Confirms the registration if possible and sends e-mails to admin and user
  *
  * @param int $reguid UID of registration
  * @param string $hmac HMAC for parameters
  *
  * @return void
  */
 public function confirmRegistrationAction($reguid, $hmac)
 {
     /* @var $registration Registration */
     list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration($reguid, $hmac);
     if ($failed === false) {
         $registration->setConfirmed(true);
         $this->registrationRepository->update($registration);
         $messageType = MessageType::REGISTRATION_CONFIRMED;
         if ($registration->getWaitlist()) {
             $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED;
         }
         // Send notifications to user and admin
         $this->notificationService->sendUserMessage($registration->getEvent(), $registration, $this->settings, $messageType);
         $this->notificationService->sendAdminMessage($registration->getEvent(), $registration, $this->settings, $messageType);
         // Confirm registrations depending on main registration if necessary
         if ($registration->getAmountOfRegistrations() > 1) {
             $this->registrationService->confirmDependingRegistrations($registration);
         }
     }
     // Redirect to payment provider if payment/redirect is enabled
     $paymentPid = (int) $this->settings['paymentPid'];
     if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
         $this->uriBuilder->reset()->setTargetPageUid($paymentPid)->setUseCacheHash(false);
         $uri = $this->uriBuilder->uriFor('redirect', ['registration' => $registration, 'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())], 'Payment', 'sfeventmgt', 'Pipayment');
         $this->redirectToUri($uri);
     }
     $this->view->assign('messageKey', $messageKey);
     $this->view->assign('titleKey', $titleKey);
 }
Пример #9
0
 /**
  * Returns the payment Uri for the given action and registration
  *
  * @param string $action
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration
  * @return string
  * @throws \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException
  */
 protected function getPaymentUriForAction($action, $registration)
 {
     $this->uriBuilder->setCreateAbsoluteUri(true)->setUseCacheHash(false);
     return $this->uriBuilder->uriFor($action, ['registration' => $registration, 'hmac' => $this->hashService->generateHmac($action . 'Action-' . $registration->getUid())], 'Payment', 'sfeventmgt', 'Pipayment');
 }
Пример #10
0
 /**
  * Serialize and hash the form field array
  *
  * @param array $formFieldArray form field array to be serialized and hashed
  * @return string Hash
  */
 protected function serializeAndHashFormFieldArray($formFieldArray)
 {
     $serializedFormFieldArray = serialize($formFieldArray);
     return $serializedFormFieldArray . $this->hashService->generateHmac($serializedFormFieldArray);
 }