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

Commit

Permalink
Add in reviews captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas van Staden committed Jul 16, 2015
1 parent 5b6ebff commit de9268a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
48 changes: 48 additions & 0 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ public function checkContact($observer)
return $this;
}

/**
* Check Captcha On Forgot Password Page
*
* @param Varien_Event_Observer $observer
* @return Mage_Captcha_Model_Observer
*/
public function checkReview($observer)
{
$formId = 'user_review';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
if ($captchaModel->isRequired()) {
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
//$controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
//$refererUrl = $this->_getRefererUrl();
//$controller->getResponse()->setRedirect($refererUrl);
//invalidate the formkey, whoich will force the controller to redirect back to referer
$controller->getRequest()->setParam('form_key', 'Incorrect CAPTCHA.');
}
}
return $this;
}

/**
* Get Captcha String
*
Expand All @@ -67,4 +91,28 @@ protected function _getCaptchaString($request, $formId)
return $captchaParams[$formId];
}

/**
* Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
*
* @return string
*/
protected function _getRefererUrl($controller)
{
$refererUrl = $controller->getRequest()->getServer('HTTP_REFERER');
if ($url = $controller->getRequest()->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL)) {
$refererUrl = $url;
}
if ($url = $controller->getRequest()->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_BASE64_URL)) {
$refererUrl = Mage::helper('core')->urlDecodeAndEscape($url);
}
if ($url = $controller->getRequest()->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_URL_ENCODED)) {
$refererUrl = Mage::helper('core')->urlDecodeAndEscape($url);
}

if (!$this->_isUrlInternal($refererUrl)) {
$refererUrl = Mage::app()->getStore()->getBaseUrl();
}
return $refererUrl;
}

}
13 changes: 12 additions & 1 deletion app/code/community/ProxiBlue/ReCaptcha/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<ProxiBlue_ReCaptcha>
<version>1.1.0</version>
<version>1.2.0</version>
<depends>
<Mage_Captcha/>
</depends>
Expand Down Expand Up @@ -38,6 +38,14 @@
</captcha>
</observers>
</controller_action_predispatch_contacts_index_post>
<controller_action_predispatch_review_product_post>
<observers>
<captcha>
<class>proxiblue_recaptcha/observer</class>
<method>checkReview</method>
</captcha>
</observers>
</controller_action_predispatch_review_product_post>
</events>
</global>
<frontend>
Expand Down Expand Up @@ -72,6 +80,9 @@
<user_contact>
<label>Contact</label>
</user_contact>
<user_review>
<label>Reviews</label>
</user_review>
</areas>
</frontend>
</captcha>
Expand Down
26 changes: 0 additions & 26 deletions app/code/community/ProxiBlue/ReCaptcha/etc/system.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
<?xml version="1.0"?>
<!--
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition License
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magentocommerce.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Captcha
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://www.magentocommerce.com/license/enterprise-edition
*/
-->
<config>
<sections>
<admin>
Expand Down
47 changes: 15 additions & 32 deletions app/design/frontend/base/default/layout/proxiblue_recaptcha.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition License
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magentocommerce.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category design
* @package base_default
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://www.magentocommerce.com/license/enterprise-edition
*/
-->
<layout version="0.1.0">
<contacts_index_index>
<reference name="contactForm">
<block type="captcha/captcha" name="recaptcha">
<reference name="head">
<action method="addJs">
<file>mage/captcha.js</file>
</action>
</reference>
<action method="setFormId">
<formId>user_contact</formId>
</action>
Expand All @@ -47,4 +15,19 @@
</block>
</reference>
</contacts_index_index>
<review_product_list>
<reference name="product.review.form">
<block type="captcha/captcha" name="recaptcha">
<action method="setFormId">
<formId>user_review</formId>
</action>
<action method="setImgWidth">
<width>230</width>
</action>
<action method="setImgHeight">
<width>50</width>
</action>
</block>
</reference>
</review_product_list>
</layout>

0 comments on commit de9268a

Please sign in to comment.