Implement 'stop forum spam' api to prevent form spam
This commit is contained in:
@@ -30,6 +30,7 @@ namespace EP\EpEvents\Controller;
|
||||
use EP\EpEvents\Domain\Model\Inquiry;
|
||||
use EP\EpEvents\Service\ConfigurationService;
|
||||
use EP\EpEvents\Service\EmailService;
|
||||
use EP\EpEvents\Service\SpamProtectService;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
@@ -46,10 +47,20 @@ class AjaxFormController extends ActionController
|
||||
*/
|
||||
protected $configurationService;
|
||||
|
||||
public function __construct(EmailService $emailService, ConfigurationService $configurationService)
|
||||
{
|
||||
/**
|
||||
* @var SpamProtectService
|
||||
*/
|
||||
protected $spamProtectService;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
EmailService $emailService,
|
||||
ConfigurationService $configurationService,
|
||||
SpamProtectService $spamProtectService
|
||||
) {
|
||||
$this->emailService = $emailService;
|
||||
$this->configurationService = $configurationService;
|
||||
$this->spamProtectService = $spamProtectService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +70,17 @@ class AjaxFormController extends ActionController
|
||||
*/
|
||||
public function processInquiryFormAction(Inquiry $inquiry)
|
||||
{
|
||||
$response['status'] = 'ok';
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Inquiry',
|
||||
'variables' => [ 'inquiry' => $inquiry ]
|
||||
]);
|
||||
return json_encode($response);
|
||||
if (false === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) {
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Inquiry',
|
||||
'variables' => [ 'inquiry' => $inquiry ]
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,25 +90,31 @@ class AjaxFormController extends ActionController
|
||||
*/
|
||||
public function processConfiguratorFormAction(Inquiry $inquiry)
|
||||
{
|
||||
$response['status'] = 'ok';
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Configurator',
|
||||
'variables' => [
|
||||
'inquiry' => $inquiry,
|
||||
'config' => $this->configurationService->getConfiguratorConfig(),
|
||||
]
|
||||
]);
|
||||
return json_encode($response);
|
||||
if (false === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) {
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Configurator',
|
||||
'variables' => [
|
||||
'inquiry' => $inquiry,
|
||||
'config' => $this->configurationService->getConfiguratorConfig(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function errorAction() {
|
||||
$formErrors = [];
|
||||
$response = [
|
||||
'status' => 'validation',
|
||||
'errors' => [],
|
||||
];
|
||||
|
||||
if ($this->arguments->validate()->hasErrors()) {
|
||||
foreach ($this->arguments->validate()->getFlattenedErrors() as $key => $errors)
|
||||
{
|
||||
@@ -106,13 +125,10 @@ class AjaxFormController extends ActionController
|
||||
$translationKey = sprintf('tx_epevents.message.%s.%s', $key, $error->getCode());
|
||||
$errorsRaw[] = LocalizationUtility::translate($translationKey, 'ep_events');
|
||||
}
|
||||
$formErrors[$key] = implode(', ', $errorsRaw);
|
||||
$response['errors'][$key] = implode(', ', $errorsRaw);
|
||||
}
|
||||
}
|
||||
|
||||
$response['status'] = 'validation';
|
||||
$response['errors'] = $formErrors;
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user