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

Commit

Permalink
remove wishlist and send a friend custom code as core now contains this
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas van Staden committed Nov 29, 2018
1 parent 8de6aea commit 881b2fd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 140 deletions.
47 changes: 6 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,54 +275,19 @@ The core functionality can easily be used to produce spam.
The process is that an account is created, then a product is added, then spam is generated via the share functionality, with spam messages in the message field.
Adding reCaptcha allows you to block this.

* 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 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
** Magento introduced wishlist capctha from 1.9.4, or with SUPEE 10975 **

<ul>
<?php echo $this->getChildHtml('recaptcha'); ?>
</ul>
The custom wishlist recaptcha code of this module was removed, favouring the core functionality.
If you require wishlist recapctha in pre 1.9.4 without SUPEE-10975, install version 2.0.1

Entered values will be retained upon incorrect captcha entry

Product Email a Friend Captcha
------------------------------

The core functionality can easily be used to produce spam.
The process is that an account is created, then a product is Emailed to a Friend, then spam is generated via the send functionality, with spam messages in the message field.
Adding reCaptcha allows you to block this.

* Enable in admin under Customer Configuration by selecting 'Email a Friend' in available forms list

Unfortunately the core Send a Friend form does not have an after form elements block, so you will need to adjust your form to display the captcha.
Additionally, the form allows you to add/remove recipients by adding/removing more recipient rows.
Some changes need to be made to the base form (copy to your own theme folder) to accommodate this functionality, else the recipients will be lost upon incorrect captcha.

The changes are done to retain the core add/remove functionality of the form.
Since these changes are fairly big, I have provided a diff which you can apply, and for reference there is also a gist with the complete form ready to use (if you have no custom changes in your theme for the ```sendfiend/send.phtml``` template, you can simply just place the provided gist file to your theme as the template ```sendfiend\send.phtml```)

[Full file](https://gist.github.com/ProxiBlue/bff88b184c9c0e44997ff6ae05468b01)
[diff](https://gist.github.com/ProxiBlue/fdf28f9bf8b678e9aa30c475d681f974)

####Explaining the changes:

[recipients counter](https://gist.github.com/ProxiBlue/bff88b184c9c0e44997ff6ae05468b01#file-gistfile1-txt-L35)
This change pre-sets the counter used to add new recipients. By default this is 0, since no recipients are initially present

[pre propulate set receipients](https://gist.github.com/ProxiBlue/bff88b184c9c0e44997ff6ae05468b01#file-gistfile1-txt-L108) Injects the already defined recipients back into the form, after any failed captcha

[inject captcha form](https://gist.github.com/ProxiBlue/bff88b184c9c0e44997ff6ae05468b01#file-gistfile1-txt-L102) ads the reCaptcha form to the display



Entered values will be retained upon incorrect captcha entry
** Magento introduced capctha from 1.9.4, or with SUPEE 10975 **

The custom recaptcha code of this module was removed, favouring the core functionality.
If you require recapctha in pre 1.9.4 without SUPEE-10975, install version 2.0.1

Newsletter Subscribe Captcha
----------------------------
Expand Down
65 changes: 0 additions & 65 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,71 +160,6 @@ 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;
}

/**
* Check Captcha On Send to Friend
*
* @param Varien_Event_Observer $observer
*
* @return Mage_Captcha_Model_Observer
*/
public function checkSendFriend($observer)
{
$formId = 'product_sendtofriend';
$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();
$productId = (int)$controller->getRequest()->getParam('id');
$catId = (int)$controller->getRequest()->getParam('cat_id');
Mage::getSingleton('catalog/session')->setData('sendfriend_form_data', $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('catalog/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
$controller->getResponse()->setRedirect(Mage::getUrl('*/*/send',array('id' => $productId, 'cat_id' => $catId)));
}
}
}
return $this;
}

/**
* Check Captcha On newsletter Subscribe
*
Expand Down
11 changes: 0 additions & 11 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
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', 'product_sendtofriend');
/**
* Key in session for captcha code
*/
Expand Down Expand Up @@ -203,10 +196,6 @@ public function isRequired($login = null)
return false;
}

if (in_array($this->_formId, $this->_alwaysShow)) {
return true;
}

return ($this->_isShowAlways() || $this->_isOverLimitAttempts($login)
|| $this->getSession()->getData($this->_getFormIdKey('show_captcha'))
);
Expand Down
24 changes: 1 addition & 23 deletions 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>2.0.1</version>
<version>2.1.0</version>
<depends>
<Mage_Captcha/>
</depends>
Expand Down Expand Up @@ -46,22 +46,6 @@
</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>
<controller_action_predispatch_sendfriend_product_sendmail>
<observers>
<captcha>
<class>proxiblue_recaptcha/observer</class>
<method>checkSendFriend</method>
</captcha>
</observers>
</controller_action_predispatch_sendfriend_product_sendmail>
<controller_action_predispatch_newsletter_subscriber_new>
<observers>
<captcha>
Expand Down Expand Up @@ -139,12 +123,6 @@
<user_review>
<label>Reviews</label>
</user_review>
<user_wishlist>
<label>Wishlist Sharing</label>
</user_wishlist>
<product_sendtofriend>
<label>Product Email to a Friend</label>
</product_sendtofriend>
<newsletter_subscribe>
<label>Newsletter Subscribe</label>
</newsletter_subscribe>
Expand Down

0 comments on commit 881b2fd

Please sign in to comment.