PHP code example of madj2k / t3-fe-register
1. Go to this page and download the library: Download madj2k/t3-fe-register library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
madj2k / t3-fe-register example snippets
/**
* Handles opt-in event
*
* @param \Madj2k\FeRegister\Domain\Model\FrontendUser $frontendUser
* @param \Madj2k\FeRegister\Domain\Model\OptIn $optIn
* @return void
* @throws \Madj2k\Postmaster\Exception
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function optIn (
\Madj2k\FeRegister\Domain\Model\FrontendUser $frontendUser,
\Madj2k\FeRegister\Domain\Model\OptIn $optIn
): void {
// get settings
$settings = $this->getSettings(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$settingsDefault = $this->getSettings();
if ($settings['view']['templateRootPaths']) {
/** @var \Madj2k\Postmaster\Mail\MailMessage $mailService */
$mailService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(MailMessage::class);
// send new user an email with token
$mailService->setTo($frontendUser, array(
'marker' => array(
'frontendUser' => $frontendUser,
'optIn' => $optIn,
'pageUid' => intval($GLOBALS['TSFE']->id),
'loginPid' => intval($settingsDefault['loginPid']),
),
));
$mailService->getQueueMail()->setSubject(
FrontendLocalizationUtility::translate(
'mailService.optInAlertUser.subject',
'your_extension',
null,
$frontendUser->getTxFeregisterLanguageKey()
)
);
$mailService->getQueueMail()->addTemplatePaths($settings['view']['templateRootPaths']);
$mailService->getQueueMail()->addPartialPaths($settings['view']['partialRootPaths']);
$mailService->getQueueMail()->setPlaintextTemplate('Email/OptInAlertUser');
$mailService->getQueueMail()->setHtmlTemplate('Email/OptInAlertUser');
$mailService->send();
}
}
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
*/
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
Madj2k\FeRegister\Registration\AbstractRegistration::class,
Madj2k\FeRegister\Registration\AbstractRegistration::SIGNAL_AFTER_CREATING_OPTIN . 'YourCategory',
Your\Extension\Service\MailService::class,
'optInAlertUser'
);
public function optInAction(string $tokenUser, string $token): void
{
/** @var \Madj2k\FeRegister\Registration\FrontendUserRegistration $registration */
$registration = $this->objectManager->get(FrontendUserRegistration::class);
$result = $registration->setFrontendUserToken($tokenUser)
->setCategory('yourExtension')
->setRequest($this->request)
->validateOptIn($token);
if ($result >= 200 && $result < 300) {
// sucessfull
} elseif ($result >= 300 && $result < 400) {
// canceled
} else {
// error / not found
}
}