diff --git a/app/code/community/ProxiBlue/ReCaptcha/Block/Captcha/Recaptcha.php b/app/code/community/ProxiBlue/ReCaptcha/Block/Captcha/Recaptcha.php old mode 100755 new mode 100644 diff --git a/app/code/community/ProxiBlue/ReCaptcha/Block/Contact.php b/app/code/community/ProxiBlue/ReCaptcha/Block/Contact.php old mode 100755 new mode 100644 diff --git a/app/code/community/ProxiBlue/ReCaptcha/Helper/Data.php b/app/code/community/ProxiBlue/ReCaptcha/Helper/Data.php old mode 100755 new mode 100644 diff --git a/app/code/community/ProxiBlue/ReCaptcha/Model/Config/Lang.php b/app/code/community/ProxiBlue/ReCaptcha/Model/Config/Lang.php old mode 100755 new mode 100644 diff --git a/app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php b/app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php index 96ab96b..80df5e5 100644 --- a/app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php +++ b/app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php @@ -200,10 +200,35 @@ public function newsletterSubscriber($observer) */ public function checkCheckout($observer) { + // both checkout forms get transposed to a form id of 'recapctha_checkout' + // ref https://github.com/ProxiBlue/reCaptcha/issues/43 + $formId = 'recapctha_checkout'; // + $captchaModel = Mage::helper('captcha')->getCaptcha($formId); + if ($captchaModel->isRequired()) { + $controller = $observer->getControllerAction(); + if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { + $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); + $result = array('error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); + } + } + return $this; + } + + /** + * Check Captcha On Checkout as Guest Page + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function checkGuestCheckout(Varien_Event_Observer $observer) + { + // both checkout forms get transposed to a form id of 'recapctha_checkout' + // ref https://github.com/ProxiBlue/reCaptcha/issues/43 + $formId = 'recapctha_checkout'; // + $captchaModel = Mage::helper('captcha')->getCaptcha($formId); $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod(); - if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) { - $formId = 'register_during_checkout'; - $captchaModel = Mage::helper('captcha')->getCaptcha($formId); + if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST) { if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { @@ -213,9 +238,23 @@ public function checkCheckout($observer) } } } - if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST) { - $formId = 'guest_checkout'; - $captchaModel = Mage::helper('captcha')->getCaptcha($formId); + return $this; + } + + /** + * Check Captcha On Checkout Register Page + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function checkRegisterCheckout($observer) + { + // both checkout forms get transposed to a form id of 'recapctha_checkout' + // ref https://github.com/ProxiBlue/reCaptcha/issues/43 + $formId = 'recapctha_checkout'; // + $captchaModel = Mage::helper('captcha')->getCaptcha($formId); + $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod(); + if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) { if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { diff --git a/app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php b/app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php old mode 100755 new mode 100644 diff --git a/app/code/community/ProxiBlue/ReCaptcha/etc/config.xml b/app/code/community/ProxiBlue/ReCaptcha/etc/config.xml old mode 100755 new mode 100644 index 3ecf3fe..8683a0a --- a/app/code/community/ProxiBlue/ReCaptcha/etc/config.xml +++ b/app/code/community/ProxiBlue/ReCaptcha/etc/config.xml @@ -2,7 +2,7 @@ - 2.3.7 + 2.3.8 @@ -62,6 +62,18 @@ + + + + proxiblue_recaptcha/observer + checkGuestCheckout + + + proxiblue_recaptcha/observer + checkRegisterCheckout + + + diff --git a/app/code/community/ProxiBlue/ReCaptcha/etc/system.xml b/app/code/community/ProxiBlue/ReCaptcha/etc/system.xml old mode 100755 new mode 100644 diff --git a/app/design/frontend/base/default/template/captcha/recaptcha.phtml b/app/design/frontend/base/default/template/captcha/recaptcha.phtml old mode 100755 new mode 100644 index 3ed44d2..3fe5f5d --- a/app/design/frontend/base/default/template/captcha/recaptcha.phtml +++ b/app/design/frontend/base/default/template/captcha/recaptcha.phtml @@ -100,8 +100,7 @@ // test if guest checkout is enabled window.parentMehod = parentMethod; var skipParent = false; - if (checkout.method == 'guest' - && document.querySelector('.captcha-image-box-guest_checkout') !== null) { + if (checkout.method == 'guest') { skipParent = true; var validator = new Validation(this.form); if (validator.validate()) { @@ -109,8 +108,7 @@ } } - if (checkout.method == 'register' - && document.querySelector('.captcha-image-box-register_during_checkout') !== null) { + if (checkout.method == 'register') { skipParent = true; var validator = new Validation(this.form); if (validator.validate()) { diff --git a/composer.json b/composer.json index 5fc519d..9978042 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "OSL-3.0", "homepage": "https://github.com/ProxiBlue/reCaptcha", "description": "Clean integration of Google reCaptcha to OpenMage", - "version": "2.3.7", + "version": "2.3.8", "authors": [ { "name": "Lucas van Staden",