2017 © Pedro Peláez
 

magento-module recaptcha

Clean integration of Google reCaptcha to magento

image

proxiblue/recaptcha

Clean integration of Google reCaptcha to magento

  • Monday, April 30, 2018
  • by proxiblue
  • Repository
  • 7 Watchers
  • 40 Stars
  • 312 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 20 Forks
  • 1 Open issues
  • 19 Versions
  • 80 % Grown

The README.md

I am currently considering archiving this module, as I no longer have the free time to continue supporting this code. as per ticket: #43, it seems there are issues in checkout with the validation of the invisible recapctha, which could be related to the usage of prototype 1.7.1, (*1)

I simply don't have the time due to paid work with deadlines to work on this at present., (*2)

If you are using this module, I suggest looking for an alternative, or fork this and continue with it as a seperate project, (*3)

reCaptcha

Drop-In Replacement of OpenMage core Captcha system with Googles reCaptcha, (*4)

http://www.proxiblue.com.au/blog/magento-recaptcha/, (*5)

Features:

  • Supports all native OpenMage captcha areas
  • Supports placing captcha into, (*6)

    • Contact Us form,
    • CMS pages (contact us in cms page),
    • Products Reviews
    • Customer Wishlist Sharing
    • Product 'Email a friend'
    • Newsletter Subscribe
  • Supports Invisible reCaptcha (now the default) with option to set badge position, (*7)

  • Supports the 'I am not a robot' reCaptcha (just in case you don't want invisible)

Requirements

  • Core onepage checkout for reCaptcha in Checkout.
  • There is no plans to extend this extension to use 3rd party checkouts, however PRs are welcomed ** Works with FireCheckout - https://github.com/ProxiBlue/reCaptcha/pull/40
  • Feel free to extend if you know how. PRs welcomed.
  • You require a bit of knowledge on how to extend theme templates. This reCaptcha does not rewrite or extend core functionality, so it does not replace theme files. Clear instructions are given. It works 'out-the-box' in all areas where core OpenMage captcha works. It is more 'developer' centric, when you don't want a reCaptcha module to make major changes to core functionality, and allows your developer to integrate into your themes. Clear instructions are given.

Installing

ATTENTION:, (*8)

Since 17/06/2021 google changed their invisible recaptcha code, which makes it incompatibile with the core version of prototype 1.7.0 which ships with vanilla magento 1. (ref: https://github.com/ProxiBlue/reCaptcha/issues/56 ) This module has been adjusted to include prototype 1.7.1 as of version 2.5.1 (least compatible version required to fix issue) - Thank you to @empiricompany for this fix. You can see the adjsuted code in PR: https://github.com/ProxiBlue/reCaptcha/pull/57, (*9)

OpenMage 19.4.12 (or the 20.x range) already ships with an updated version of Prototype. You should really be sporting that update on a live site., (*10)

ADMIN LOGIN NEEDS MANUAL INTERVENTION, (*11)

Core magento hardcoded the inclusion of the default prototype 1.7.0 in the following admin files:, (*12)

app/design/adminhtml/default/default/template/resetforgottenpassword.phtml
app/design/adminhtml/default/default/template/login.phtml
app/design/adminhtml/default/default/template/forgotpassword.phtml

You need to manually adjust these files to change the line:, (*13)

<script type="text/javascript" src="<?php echo $this->getJsUrl('prototype/prototype.js') ?>"></script>

to, (*14)

<script type="text/javascript" src="<?php echo $this->getJsUrl('proxiblue/recaptcha/prototype.js') ?>"></script>

There is no clean fix for this., (*15)

Alternatively you can disable admin login reCapctha (and secure your admin via 2fa and firewall access) OR you can simply replace the core prototype file with an updated version of 1.7.1 (ie copy the prodiblue version over the core version, and use that), (*16)

VERSIONS:

If you have magento 1.9.4, OR you have Magento < 1.9.4 + SUPEE 10975 patch installed, you must use release 2.1.x or greater. If you have Magento < 1.9.4 and not pacthed with SUPEE 10975, then you must use version 2.0.1 (the most up-to-date version prior to 1.9.4 and SUPEE 10975 patch) If you have OpenMage use release 2.1.x or greater., (*17)

Your should patch to SUPEE 10975 else your store is a security risk!, (*18)

All:

  • if captcha is enabled, disable it. including for admin

By GIT:

  • clone this repo
  • disable compilation if you use that.
  • copy the files from the repo into the base folder of your magento / OpenMage install
  • clear your cache
  • re-enable compilation

By Composer:

Direct from GitHub repo:

  • disable compilation (mageno 1 only, OpenMage have removed the compilation feature), (*19)

  • Update the following to sections in your composer file:, (*20)

   "require": {
       "proxiblue/recaptcha": "*"
   },
   "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/ProxiBlue/reCaptcha.git"
        }
    ],
  • Update composer: composer update
  • Clear cache
  • re-enable compilation (mageno 1 only, OpenMage have removed the compilation feature)

Using composer package:

In the root of your OpenMage install, run the following commands:, (*21)

composer config repositories.github.repo.repman.io composer https://github.repo.repman.io

Disabling:

  • Disable compilation
  • Edit the file /app/etc/modules/ProxiBlue_ReCaptcha.xml, and set the active to false.
  • Remove any theme captcha insertion code as described below in all sections
  • Clear Cache
  • Enable compilation

This should not happen, but if you uninstall the module, you could run into an error that the recaptcha block is not available, (*22)

exception 'Mage_Core_Exception' with message 'Invalid block type: ProxiBlue_ReCaptcha_Block_Captcha_Recaptcha', (*23)

You need to remove two entries from the core table core_config_data (one for admin, one for frontend), (*24)

  • access your database via your prefered MySQL admin tool (for example PHPMyAdmin)
  • run: ```DELETE FROM core_config_data WHERE path = 'customer/capctha/type';
  • run: ```DELETE FROM core_config_data WHERE path = 'admin/capctha/type';
  • clear your cache by deleting the var/cache folder

if you use n98-magerun:, (*25)

  • n98-magerun config:delete customer/capctha/type
  • n98-magerun config:delete admin/capctha/type
  • n98-magerun cache:clean

Setup:

  • Obtain your site public key (Site Key) and private key (Secret Key) for your domain and recaptcha usage
  • Note that Invisible requires new keys, and existing keys for 'I am not a robot' will NOT work!
  • Enter these in the admin settings for captcha.

You can get testing/developer keys here: https://developers.google.com/recaptcha/docs/faq, (*26)

V1 Captcha support dropped

Since 1.4.0 all v1 captcha (pre I am not a Robot) has been removed., (*27)

Disable / Enable form submit buttons

From 1.4.0 you can add the class 'enable-captcha-clicked' to any element and add the 'disabled' property to that element. After clicked, the element will be enabled., (*28)

example:, (*29)

<button type="submit" class="btn btn-primary enable-captcha-clicked" disabled="disabled">Submit</button>

Making captcha work in magento 1.9 (RWD theme)

Captcha was disabled in the RWD theme that magento 1.9 uses., (*30)

This was done by simply placing an empty layout xml file into the theme., (*31)

To make captcha work in magento 1.9:, (*32)

  • Place a copy of the base captcha.xml file into your own theme layout folder., (*33)

    cp app/design/frontend/base/default/layout/captcha.xml app/design/frontend/YOUR_PACKAGE/THEME/layout/captcha.xml, (*34)

  • or, delete that file from the rwd theme to fallback to base,, (*35)

    rm app/design/frontend/rwd/default/layout/captcha.xml, (*36)

ref: http://magento.stackexchange.com/questions/40788/captcha-is-not-visible-at-frontend-login-register-form-for-rwd-theme, (*37)

Contact Us Captcha

  • Enable in admin under Customer Configuration by selecting COntacts in available forms list
  • Unfortunately the core contact us form does not have before or after form elements block, so you will need to adjust your contact us form to display the capctha., (*38)

    Edit the contact form located here:, (*39)

    app/design/frontend/[rwd|base|your package]/[default|your theme]/template/contacts/form.phtml, (*40)

    place the following line into the form, anywhere between <ul class="form-list"> and closing <ul> elements in the form, (*41)

    getChildHtml('recaptcha'); ?>

Unfortunately magento core templates do not accommodate reloading the posted form data. This means that if the captcha was incorrect, the user will be given a new blank form. Obviously not ideal., (*42)

The captcha extension places the form data into the customer session, aptly named 'formData', using the following lines of code, (*43)

$data = $controller->getRequest()->getPost();
Mage::getSingleton('customer/session')->setFormData($data);

You can re-populate the form data using the information stored in the session. This will require you to make some changes to the form.phtml file. It is really up to you how you will retrieve and use the session data. As an example, you can do this at the top of the template form.phtml:, (*44)

$formData = new Varien_Object();
$formData->setData(Mage::getSingleton('customer/session')->getFormData());

The posted data is now held in the Varien Object called $formData You can pre-populate the data as such:, (*45)

$_firstname = ($formData->getFirstname())?$formData->getFirstname():$this->helper('contacts')->getFirstName();
$_lastname = ($formData->getLastname())?$formData->getLastname():$this->helper('contacts')->getLastName();
$_email = ($formData->getEmail())?$formData->getEmail():$this->helper('contacts')->getEmail();
$_telephone = ($formData->getTelephone())?$formData->getTelephone():'';
$_suburb = ($formData->getSuburb())?$formData->getSuburb():'';
$_postcode = ($formData->getPostcode())?$formData->getPostcode():'';
$_comment = ($formData->getComment())?$formData->getComment():'';

and in the template, simply echo out the values held in the definded variables: An example is as such:, (*46)

<input name="firstname" id="firstname" title="<?php echo Mage::helper('contacts')->__('First Name') ?>" value="<?php echo $this->htmlEscape($_firstname) ?>" class="input-text required-entry" type="text" />

Submitting Contact Us via AJAX

From version 1.3.0, you can pass two additional params via an AJAX submitted form. The response form the module will then be a JSON string denoting if the captcha failed., (*47)

Example AJAX call to submit a contact us form:, (*48)

 $j.ajax({
     url: $j('#contactForm').attr('action'),
     type: 'POST',
     data: {
         help: $j("#help").val(),
         firstname: $j("#firstname").val(),
         lastname: $j("#lastname").val(),
         email: $j("#email-address").val(),
         telephone: $j("#telephone").val(),
         suburb: $j("#suburb").val(),
         postcode: $j("#postcode").val(),
         comment: $j("#comment").val(),
         about: $j("#about").val(),
         consultant: $j("#consultant").val(),
         json: 1,
         gcr: $j("#g-recaptcha-response").val()
     },
     success: function (result, xhr) {
         try {
             var result = jQuery.parseJSON(result);
         } catch (err) {
             // fail silently as result was not JSON, so could be success
         }
         if(typeof result =='object') {
             if (result.error) {
                 alert(result.error);
             }
         } else {
             // assume a success as not capctha error
             // deal with any other form errors here.
         }
     },
     error: function (xhr, err) {
         alert(err);
     }
 });
 event.preventDefault();
 return false;

Note the inclusion of two extra variables in the POST:, (*49)

 json: 1,
 gcr: $j("#g-recaptcha-response").val()

Use in Checkout OnePage

Selecting 'Checkout as Guest' or 'Register at checkout' no longer has a ny difference in the outcome of checkout reCaptcha If EITHER is selected, you will have an active reCapctha at the BILLING section. This is due to how invisible reCacptha works on the page, and I currently see no need to make this work individually, (*50)

Use Contact Form in CMS Page

You can Place the Contact Us form within a CMS page using the following Block notation:, (*51)

 <ul>
 {{block type="proxiblue_recaptcha/contact" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
 </ul>

Remember to add the custom block to your allowed blocks in System->Permissions->Blocks. Use proxiblue_recaptcha/contact, (*52)

Product Review Captcha

  • Enable in admin under Customer Configuration by selecting 'reviews' in available forms list
  • Unfortunately the core product review form does not have an after form elements block, so you will need to adjust your reviews form to display the captcha., (*53)

    Edit the reviews form located here:, (*54)

    app/design/frontend/[rwd|base|your package]/[default|your theme]/template/review/form.phtml, (*55)

    place the following line into the form, anywhere between the form elements., (*56)

      getChildHtml('recaptcha'); ?>

Customer Wishlist Sharing Captcha

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., (*57)

** Magento introduced wishlist capctha from 1.9.4, or with SUPEE 10975 **, (*58)

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, (*59)

Product Email a Friend Captcha

** Magento introduced capctha from 1.9.4, or with SUPEE 10975 **, (*60)

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, (*61)

Newsletter Subscribe Captcha

Most sites have newsletter subscribe option, on every page. This is a big source for spam. With invisible recaptcha option you can limit this now, without adding extra effort for user to subscribe., (*62)

To make reCaptcha appear on subscriber form/page, you need to edit this template:, (*63)

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

Place the following code between the <form> and closing </form> elements:, (*64)



    getChildHtml('recaptcha'); ?>

Ensure options are set in admin to allow recaptcha for newsletter, and using Invisible reCaptcha is recommeded, (*65)

Newsletter Subscribe in CMS Page

You can Place the Newsletter Subscription form within a CMS page using the following Block notation:, (*66)

{{block type="proxiblue_recaptcha/subscribe" template="newsletter/subscribe.phtml"}

Remember to add the custom block to your allowed blocks in System->Permissions->Blocks. Use proxiblue_recaptcha/subscribe, (*67)

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

Some possibilities:, (*68)

  • You are using a custom theme package, and the reCaptcha layout directive file is not loaded.
  • You are using a custom theme and the fallback to the base theme is not picking up the layout file.

To fix this, simply copy the file, (*69)

app/design/frontend/base/default/layout/proxiblue_recaptcha.xml

to your package or theme folder, which will be located something like such:, (*70)

app/design/frontend/<PACKAGE_NAME>/<THEME NAME>/layout/proxiblue_recaptcha.xml
  • You have directives in your custom theme that changes how the review and customer screen layouts are built.

There can be quite a few ways that your custom theme/package changed this. The most common would be in your local.xml file, located at app/design/frontend/<PACKAGE_NAME>/<THEME NAME>/layout/local.xml In that file, locate the relevant sections as noted in the reCaptcha layout file (https://github.com/ProxiBlue/reCaptcha/blob/master/app/design/frontend/base/default/layout/proxiblue_recaptcha.xml) Insert into the layout sections the relevant reCaptcha parts., (*71)

For example, if you have this section in your lcoal.xml file, (*72)

<review_product_list>
</review_product_list>

copy the entire section from the reCaptcha layout over into that section., (*73)

<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>

If, you also have the following: <reference name="product.review.form"> then only copy the BLOCK definition part into that reference., (*74)

  • It may be you have old captcha settings stuck in db, and they need to be cleared out.

Run this SQL against your db: DELETE FROM core_config_data where path like '%captcha%' This will also wipe your api keys, so you will need to re-setup admin., (*75)

Admin Forgot password is not working

This is NOT caused by the recapctha module/code, and is a core bug, (*76)

ref: https://magento.stackexchange.com/questions/125453/admin-forgot-password-does-not-work-with-x-content-type-options-nosniff-header, (*77)

There are multiple options for 'Wishlist and Product sharing' optiosn in admin form

You are running version <= 2.0.1 on a more up-to-date version of core. Upgrade the module past 2.0.1, (*78)

You need to clear out the old admin config, and resetup the required forms:, (*79)

delete from core_config_data where path = 'customer/captcha/forms';
delete from core_config_data where path = 'admin/captcha/forms';

Our Premium extensions:

Magento Dynamic Category Products Automate Category Product associations - assign any product to a category, using various rules., (*80)

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

05/04 2018

v1.7.0

1.7.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

27/01 2018

1.6.0

1.6.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

27/01 2018

1.5.1

1.5.1.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

26/01 2018

1.5.0

1.5.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

20/12 2017

1.4.1

1.4.1.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

23/11 2017

1.4.0

1.4.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

05/10 2017

1.3.0

1.3.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

06/04 2017

1.2.9

1.2.9.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

14/03 2017

1.2.8

1.2.8.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

19/11 2016

1.2.7

1.2.7.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

28/08 2016

1.2.5

1.2.5.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

11/08 2015

1.2.3

1.2.3.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

30/07 2015

1.2.2

1.2.2.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

16/07 2015

1.2.1

1.2.1.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

16/07 2015

1.2.0

1.2.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

01/04 2015

1.1.1

1.1.1.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

29/03 2015

1.1

1.1.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden

29/03 2015

1.0

1.0.0.0 https://github.com/ProxiBlue/reCaptcha

Clean integration of Google reCaptcha to magento

  Sources   Download

OSL-3.0

The Requires

 

by Lucas van Staden