From a61927d9a1fdd8693029142c43b197bd9ca4fae1 Mon Sep 17 00:00:00 2001 From: jcournut Date: Wed, 23 Mar 2022 10:46:03 +0100 Subject: [PATCH] fix multiple recaptcha invisible --- Config/config.xml | 4 +- Config/module.xml | 2 +- Hook/HookManager.php | 33 ++++++++++- .../default/recaptcha-js-invisible.html | 56 +++++++++++++++++++ .../frontOffice/default/recaptcha-js.html | 11 ++-- 5 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 templates/frontOffice/default/recaptcha-js-invisible.html diff --git a/Config/config.xml b/Config/config.xml index f955ea0..812f341 100644 --- a/Config/config.xml +++ b/Config/config.xml @@ -33,8 +33,8 @@ - - + + diff --git a/Config/module.xml b/Config/module.xml index 717776d..0d42cf1 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 2.0.3 + 2.0.4 Vincent Lopes-Vicente diff --git a/Hook/HookManager.php b/Hook/HookManager.php index 9fc3f5b..18ce235 100644 --- a/Hook/HookManager.php +++ b/Hook/HookManager.php @@ -39,13 +39,44 @@ public function addRecaptchaCheck(HookRenderEvent $event) $captchaId= "recaptcha"; $captchaCallback = ""; + $type = ""; + if ($captchaStyle === 'invisible') { $captchaCallback = "data-callback='onCompleted'"; + $type = "g-invisible"; $captchaId .= '-invisible'; } - $event->add("
"); + if (null !== $event->getArgument('id')) { + $captchaId = $event->getArgument('id'); + } + + $event->add("
"); } + public function loadRecaptcha(HookRenderEvent $event) + { + $siteKey = ReCaptcha::getConfigValue('site_key'); + $captchaStyle = ReCaptcha::getConfigValue('captcha_style'); + + if ($captchaStyle !== 'invisible') { + $event->add($this->render( + 'recaptcha-js.html', + [ + "siteKey" => $siteKey, + "captchaStyle" => $captchaStyle, + ] + )); + + return; + } + $event->add($this->render( + 'recaptcha-js-invisible.html', + [ + "siteKey" => $siteKey, + "captchaStyle" => $captchaStyle, + ] + )); + } } diff --git a/templates/frontOffice/default/recaptcha-js-invisible.html b/templates/frontOffice/default/recaptcha-js-invisible.html new file mode 100644 index 0000000..7164ae3 --- /dev/null +++ b/templates/frontOffice/default/recaptcha-js-invisible.html @@ -0,0 +1,56 @@ + + + + + +{literal} + +{/literal} \ No newline at end of file diff --git a/templates/frontOffice/default/recaptcha-js.html b/templates/frontOffice/default/recaptcha-js.html index 40e662c..e64a79c 100644 --- a/templates/frontOffice/default/recaptcha-js.html +++ b/templates/frontOffice/default/recaptcha-js.html @@ -1,22 +1,23 @@ - + + \ No newline at end of file