Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Fix register no longer validatng
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas committed Feb 5, 2021
1 parent 1f2f0d6 commit 50b6917
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 12 deletions.
Empty file.
Empty file modified app/code/community/ProxiBlue/ReCaptcha/Block/Contact.php
100755 → 100644
Empty file.
Empty file modified app/code/community/ProxiBlue/ReCaptcha/Helper/Data.php
100755 → 100644
Empty file.
Empty file modified app/code/community/ProxiBlue/ReCaptcha/Model/Config/Lang.php
100755 → 100644
Empty file.
51 changes: 45 additions & 6 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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))) {
Expand Down
Empty file modified app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php
100755 → 100644
Empty file.
14 changes: 13 additions & 1 deletion app/code/community/ProxiBlue/ReCaptcha/etc/config.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<ProxiBlue_ReCaptcha>
<version>2.3.7</version>
<version>2.3.8</version>
<depends>
<Mage_Captcha/>
</depends>
Expand Down Expand Up @@ -62,6 +62,18 @@
</captcha_guest>
</observers>
</controller_action_predispatch_checkout_onepage_savebilling>
<controller_action_predispatch_checkout_onepage_savebilling>
<observers>
<captcha_guest>
<class>proxiblue_recaptcha/observer</class>
<method>checkGuestCheckout</method>
</captcha_guest>
<captcha_register>
<class>proxiblue_recaptcha/observer</class>
<method>checkRegisterCheckout</method>
</captcha_register>
</observers>
</controller_action_predispatch_checkout_onepage_savebilling>
</events>
</global>
<adminhtml>
Expand Down
Empty file modified app/code/community/ProxiBlue/ReCaptcha/etc/system.xml
100755 → 100644
Empty file.
6 changes: 2 additions & 4 deletions app/design/frontend/base/default/template/captcha/recaptcha.phtml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@
// 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()) {
grecaptcha.execute();
}

}
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()) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 50b6917

Please sign in to comment.