Commit 1dee6015 authored by Tino Goratsch's avatar Tino Goratsch

added the recaptcha specific form validation

parent 728bd2d9
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Captcha\Event\Listener;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Validation\Event\FormValidationEvent;
use ACP3\Core\Validation\ValidationRules\NotEmptyValidationRule;
class OnCaptchaValidationAdminSettingsCustomFieldsListener
{
/**
* @var Translator
*/
private $translator;
/**
* OnCaptchaValidationAdminSettingsCustomFieldsListener constructor.
* @param Translator $translator
*/
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
/**
* @param FormValidationEvent $event
*/
public function validateRecaptchaSettings(FormValidationEvent $event)
{
$formData = $event->getFormData();
if ($this->isRecaptcha($formData)) {
$event->getValidator()
->addConstraint(NotEmptyValidationRule::class, [
'data' => $formData,
'field' => 'recaptcha_sitekey',
'message' => $this->translator->t('captcha', 'type_in_recaptcha_sitekey')
])
->addConstraint(NotEmptyValidationRule::class, [
'data' => $formData,
'field' => 'recaptcha_secret',
'message' => $this->translator->t('captcha', 'type_in_recaptcha_secret')
]);
}
}
/**
* @param array $formData
* @return bool
*/
private function isRecaptcha(array $formData)
{
return !empty($formData['captcha']) && $formData['captcha'] === 'captcha.extension.recaptcha_captcha_extension';
}
}
......@@ -14,6 +14,13 @@ services:
tags:
- { name: core.eventListener, event: captcha.admin_settings.custom_fields, method: renderRecaptchaSettings }
captcha.event.on_captcha_validation_admin_settings_custom_fields_listener:
class: ACP3\Modules\ACP3\Captcha\Event\Listener\OnCaptchaValidationAdminSettingsCustomFieldsListener
arguments:
- '@core.lang'
tags:
- { name: core.eventListener, event: captcha.validation.admin_settings.custom_fields, method: validateRecaptchaSettings }
captcha.event.on_captcha_validation_validate_captcha_listener:
class: ACP3\Modules\ACP3\Captcha\Event\Listener\OnCaptchaValidationValidateCaptchaListener
arguments:
......
......@@ -15,5 +15,7 @@
<item key="recaptcha_secret">reCAPTCHA Secret</item>
<item key="recaptcha_sitekey">reCAPTCHA Sitekey</item>
<item key="select_captcha_type">Bitte wählen Sie den zu verwendenten Captcha-Typen aus.</item>
<item key="type_in_recaptcha_secret">Bitte geben Sie das reCAPTCHA Secret ein.</item>
<item key="type_in_recaptcha_sitekey">Bitte geben Sie den reCAPTCHA Sitekey ein.</item>
</keys>
</language>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment