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

Commit 1f2f0d6

Browse files
author
Lucas
committed
fix issue #43
1 parent 4aa3fa1 commit 1f2f0d6

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,41 @@ public function newsletterSubscriber($observer)
192192
return $this;
193193
}
194194

195+
/**
196+
* Check Captcha On Checkout Register Page
197+
*
198+
* @param Varien_Event_Observer $observer
199+
* @return $this
200+
*/
201+
public function checkCheckout($observer)
202+
{
203+
$checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod();
204+
if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) {
205+
$formId = 'register_during_checkout';
206+
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
207+
if ($captchaModel->isRequired()) {
208+
$controller = $observer->getControllerAction();
209+
if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
210+
$controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
211+
$result = array('error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
212+
$controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
213+
}
214+
}
215+
}
216+
if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST) {
217+
$formId = 'guest_checkout';
218+
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
219+
if ($captchaModel->isRequired()) {
220+
$controller = $observer->getControllerAction();
221+
if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
222+
$controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
223+
$result = array('error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
224+
$controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
225+
}
226+
}
227+
}
228+
return $this;
229+
}
230+
195231

196232
}

app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ public function getElementId($type = 'input')
194194
public function isRequired($login = null)
195195
{
196196
if(!$this->_isEnabled() || !in_array($this->_formId, $this->_getTargetForms())){
197+
if($this->_formId == 'recapctha_checkout') {
198+
return true;
199+
}
197200
return false;
198201
}
199202

@@ -208,4 +211,35 @@ private function _debug($message) {
208211
Mage::log($message, null, 'recapctha.log');
209212
}
210213
}
214+
215+
/**
216+
* Retrieve list of forms where captcha must be shown
217+
*
218+
* For frontend this list is based on current website
219+
*
220+
* @return array
221+
*/
222+
protected function _getTargetForms()
223+
{
224+
$formsString = (string) $this->_getHelper()->getConfigNode('forms');
225+
$forms = explode(',', $formsString);
226+
// remove either checkout as guest or register at checkout, and if either is there, replace with a generic checkout
227+
if (($key = array_search('register_during_checkout', $forms)) !== false) {
228+
unset($forms[$key]);
229+
if (Mage::registry('has_recapctha') == false && $this->_formId == 'register_during_checkout') {
230+
$forms[] = 'recapctha_checkout';
231+
$this->_formId = 'recapctha_checkout';
232+
Mage::register('has_recapctha', true, true);
233+
}
234+
}
235+
if (($key = array_search('guest_checkout', $forms)) !== false) {
236+
unset($forms[$key]);
237+
if (Mage::registry('has_recapctha') == false && $this->_formId == 'guest_checkout') {
238+
$forms[] = 'recapctha_checkout';
239+
$this->_formId = 'recapctha_checkout';
240+
Mage::register('has_recapctha', true, true);
241+
}
242+
}
243+
return array_unique($forms);
244+
}
211245
}

app/code/community/ProxiBlue/ReCaptcha/etc/config.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<ProxiBlue_ReCaptcha>
5-
<version>2.3.4</version>
5+
<version>2.3.7</version>
66
<depends>
77
<Mage_Captcha/>
88
</depends>
@@ -54,6 +54,14 @@
5454
</captcha>
5555
</observers>
5656
</controller_action_predispatch_newsletter_subscriber_new>
57+
<controller_action_predispatch_checkout_onepage_savebilling>
58+
<observers>
59+
<captcha_guest>
60+
<class>proxiblue_recaptcha/observer</class>
61+
<method>checkCheckout</method>
62+
</captcha_guest>
63+
</observers>
64+
</controller_action_predispatch_checkout_onepage_savebilling>
5765
</events>
5866
</global>
5967
<adminhtml>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "OSL-3.0",
55
"homepage": "https://github.com/ProxiBlue/reCaptcha",
66
"description": "Clean integration of Google reCaptcha to OpenMage",
7-
"version": "2.3.6",
7+
"version": "2.3.7",
88
"authors": [
99
{
1010
"name": "Lucas van Staden",

0 commit comments

Comments
 (0)