diff --git a/local/modules/Front/Controller/ContactController.php b/local/modules/Front/Controller/ContactController.php index fa398328..acb8806a 100644 --- a/local/modules/Front/Controller/ContactController.php +++ b/local/modules/Front/Controller/ContactController.php @@ -50,15 +50,6 @@ class ContactController extends BaseFrontController try { $form = $this->validateForm($contactForm); - $checkModule = ModuleQuery::create() - ->findOneByCode('ReCaptcha'); - - if($checkModule && $checkModule->getActivate()){ - $checkCaptchaEvent = new ReCaptchaCheckEvent(); - $this->dispatch(ReCaptchaEvents::CHECK_CAPTCHA_EVENT, $checkCaptchaEvent); - if ($checkCaptchaEvent->isHuman() == false) { throw new FormValidationException('Veuillez confirmer que vous n\'êtes pas un robot.'); } - } - $this->getMailer()->sendSimpleEmailMessage( [ ConfigQuery::getStoreEmail() => $form->get('name')->getData() ], [ ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName() ], diff --git a/local/modules/Front/Controller/CustomerController.php b/local/modules/Front/Controller/CustomerController.php index 56b9f5d9..9e414458 100644 --- a/local/modules/Front/Controller/CustomerController.php +++ b/local/modules/Front/Controller/CustomerController.php @@ -164,18 +164,7 @@ class CustomerController extends BaseFrontController try { $form = $this->validateForm($customerCreation, "post"); - - $checkModule = ModuleQuery::create() - ->findOneByCode('ReCaptcha'); - - if($checkModule && $checkModule->getActivate()){ - $checkCaptchaEvent = new ReCaptchaCheckEvent(); - $this->dispatch(ReCaptchaEvents::CHECK_CAPTCHA_EVENT, $checkCaptchaEvent); - if ($checkCaptchaEvent->isHuman() == false) { throw new \Exception('Veuillez confirmer que vous n\'êtes pas un robot.'); } - } - $customerCreateEvent = $this->createEventInstance($form->getData()); - $this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent); $newCustomer = $customerCreateEvent->getCustomer(); diff --git a/local/modules/ReCaptcha/Config/config.xml b/local/modules/ReCaptcha/Config/config.xml index 2bcf4598..cd1a76d4 100644 --- a/local/modules/ReCaptcha/Config/config.xml +++ b/local/modules/ReCaptcha/Config/config.xml @@ -25,6 +25,11 @@ + + + %kernel.environment% + + diff --git a/local/modules/ReCaptcha/Form/MyTheliaFormValidator.php b/local/modules/ReCaptcha/Form/MyTheliaFormValidator.php new file mode 100644 index 00000000..ff852e88 --- /dev/null +++ b/local/modules/ReCaptcha/Form/MyTheliaFormValidator.php @@ -0,0 +1,39 @@ +dispatcher = $dispatcher; + + parent::__construct($translator, $environment); + } + + public function validateForm(BaseForm $aBaseForm, $expectedMethod = null) + { + if ($aBaseForm->getRequest()->get('captcha')) { + $checkCaptchaEvent = new ReCaptchaCheckEvent(); + $this->dispatcher->dispatch(ReCaptchaEvents::CHECK_CAPTCHA_EVENT, $checkCaptchaEvent); + if ($checkCaptchaEvent->isHuman() == false) { + throw new FormValidationException('Veuillez confirmer que vous n\'êtes pas un robot.'); + } + } + + return parent::validateForm($aBaseForm, $expectedMethod); // TODO: Change the autogenerated stub + } + +} \ No newline at end of file diff --git a/local/modules/ReCaptcha/Hook/FrontHook.php b/local/modules/ReCaptcha/Hook/FrontHook.php index cbcd3cef..37d3fd5e 100644 --- a/local/modules/ReCaptcha/Hook/FrontHook.php +++ b/local/modules/ReCaptcha/Hook/FrontHook.php @@ -22,6 +22,6 @@ class FrontHook extends BaseHook $captchaId = $captchaId.'-invisible'; } - $event->add("
"); + $event->add("
"); } }