diff --git a/Config/module.xml b/Config/module.xml index fbb5010..cba7338 100755 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 2.0.0 + 2.0.1 Julien Chanséaume jchanseaume@openstudio.fr diff --git a/EventListener/AddCommentListener.php b/EventListener/AddCommentListener.php new file mode 100644 index 0000000..5de4abf --- /dev/null +++ b/EventListener/AddCommentListener.php @@ -0,0 +1,50 @@ +eventDispatcher = $eventDispatcher; + $this->requestStack = $requestStack; + } + + public function checkCaptcha(CommentCreateEvent $event) + { + $currentRequest = $this->requestStack->getCurrentRequest(); + if (!$currentRequest->request->has('admin_add_comment')) { + return; + } + + if (null !== ModuleQuery::create()->filterByCode("ReCaptcha")->filterByActivate(1)->findOne()) { + $checkCaptchaEvent = new ReCaptchaCheckEvent(); + $this->eventDispatcher->dispatch($checkCaptchaEvent, ReCaptchaEvents::CHECK_CAPTCHA_EVENT); + if ($checkCaptchaEvent->isHuman() == false) { + throw new \Exception('Invalid captcha'); + } + } + } + + public static function getSubscribedEvents() + { + return [ + CommentEvents::COMMENT_CREATE => ['checkCaptcha', 256], + ]; + } +}