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

Commit

Permalink
Add wishlist sharing recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
ProxiBlue committed Jan 26, 2018
1 parent 5876286 commit 57a98b7
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ By Composer:
* Clear cache
* re-enable compilation

By Magento Connect 1:
---------------------

Check version number available via connect against what is in GIT. It is most likely that the connect package is dated, and it is prefered to install via composer or direct from git.

Disabling:
==========
Expand Down Expand Up @@ -224,6 +220,23 @@ Product Review Captcha

<?php echo $this->getChildHtml('recaptcha'); ?>

Customer Wishlist Sharing Captcha
-------------------------

* Enable in admin under Customer Configuration by selecting 'Wishlist Sharing' in available forms list
* Unfortunately the core wishlist sharing form does not have an after form elements block, so you will need to adjust your reviews form to display the captcha.

Edit the wishlist sharing form located here:

app/design/frontend/[rwd|base|your package]/[default|your theme]/template/wishlist/sharing.phtml

place the following line into the form, anywhere within the ```<ul class="form-list">``` element.
a good place will be just before the closing ```</ul>``` tag

<?php echo $this->getChildHtml('recaptcha'); ?>

Entered values will be retained upon incorrect captcha entry

Captcha is still not appearing, even after I did the steps above!
-----------------------------------------------------------------

Expand Down
32 changes: 32 additions & 0 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,37 @@ protected function _isUrlInternal($url)
return false;
}

/**
* Check Captcha On Whislist Sharing
*
* @param Varien_Event_Observer $observer
*
* @return Mage_Captcha_Model_Observer
*/
public function checkWishlist($observer)
{
$formId = 'user_wishlist';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
if ($captchaModel->isRequired()) {
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
$request = $controller->getRequest();
$isAjax = $request->getParam('json');
// insert form data to session, allowing to re-populate the contact us form
$data = $controller->getRequest()->getPost();
Mage::getSingleton('wishlist/session')->setData('sharing_form', $data);
$controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
if($isAjax) {
$controller->getResponse()->setBody(Zend_Json::encode(array('error'=>Mage::helper('captcha')->__('Incorrect CAPTCHA.'))));
} else {
Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
$controller->getResponse()->setRedirect(Mage::getUrl('*/*/share'));
}
}
}

return $this;
}


}
28 changes: 28 additions & 0 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
class ProxiBlue_ReCaptcha_Model_Recaptcha extends Mage_Captcha_Model_Zend implements Mage_Captcha_Model_Interface
{

/**
* @var array
*
* normally recaptcha will not show for logged in users. Form ids listed here will also appear when logged in
*
*/
protected $_alwaysShow = array('user_wishlist');
/**
* Key in session for captcha code
*/
Expand Down Expand Up @@ -163,4 +170,25 @@ public function getElementId($type = 'input')
{
return 'captcha-' . $type . '-box-' . trim($this->_formId);
}

/**
* Whether captcha is required to be inserted to this form
*
* @param null|string $login
* @return bool
*/
public function isRequired($login = null)
{
if (in_array($this->_formId, $this->_alwaysShow)) {
return true;
}

if ($this->_isUserAuth() || !$this->_isEnabled() || !in_array($this->_formId, $this->_getTargetForms())) {
return false;
}

return ($this->_isShowAlways() || $this->_isOverLimitAttempts($login)
|| $this->getSession()->getData($this->_getFormIdKey('show_captcha'))
);
}
}
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.4.1</version>
<version>1.5.0</version>
<depends>
<Mage_Captcha/>
</depends>
Expand Down Expand Up @@ -46,6 +46,14 @@
</captcha>
</observers>
</controller_action_predispatch_review_product_post>
<controller_action_predispatch_wishlist_index_send>
<observers>
<captcha>
<class>proxiblue_recaptcha/observer</class>
<method>checkWishlist</method>
</captcha>
</observers>
</controller_action_predispatch_wishlist_index_send>
</events>
</global>
<adminhtml>
Expand Down Expand Up @@ -115,6 +123,9 @@
<user_review>
<label>Reviews</label>
</user_review>
<user_wishlist>
<label>Wishlist Sharing</label>
</user_wishlist>
</areas>
</frontend>
</captcha>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@
</block>
</reference>
</checkout_onepage_review>
<wishlist_index_share translate="label">
<reference name="wishlist.sharing">
<block type="captcha/captcha" name="recaptcha">
<action method="setFormId">
<formId>user_wishlist</formId>
</action>
</block>
</reference>
</wishlist_index_share>
</layout>

0 comments on commit 57a98b7

Please sign in to comment.