nenes25 / eicaptcha

Captcha module for prestashop
295 stars 84 forks source link

Form-field g-recaptcha-response is missing from $_POST when using One-Page-Checkout because of order-opc.js #103

Closed framethrower closed 3 years ago

framethrower commented 5 years ago

Your prestashop version

1.6.1.23

Eicaptcha Version

0.4.16, but that's not important

Do you use a specific theme

(Customized) default-bootstrap

Issue description

We are using (a somewhat customized) One-Page-Checkout.

There is one issue that could be resolved using metacreo's workaround.

But another issue is, that "#g-recaptcha-response"-textarea is not processed in /themes/default-bootstrap-77designz/js/order-opc.js. That means that the response from google will not be available in $_POST in hookActionBeforeSubmitAccount() in eicaptcha.php

I had to insert the following line on line 178 of order-opc.js:

params += 'g-recaptcha-response='+encodeURIComponent($('#g-recaptcha-response').val())+'&';

I'm not sure how to fix this issue from within the eicaptcha-module, as the core template is at fault here. I noticed that regular text-inputs are not affected. But i don't know if the google recaptcha can be convinced to use a text-input instead of a textarea.

Just wanted to let you know.

Thx for your work! :)

nenes25 commented 5 years ago

Hi, Thanks for the feedback , i'll check if and how it is possible to fix it without touching core files.

Regards,

osaya commented 5 years ago

Hello, I've done something like this - a bypass.

Added input in hookDisplayCustomerAccountForm.tpl for compatibility with order-opc.js:

<input type="hidden" id="recaptcha-hidden" name="g-recaptcha-response" />

And rewrite a little eicaptcha.js to assign value:

$("#submitAccount, #submitGuestAccount").on("click", function () {

    var recap = grecaptcha.getResponse();
    $('#recaptcha-hidden').val(recap);

    //Affichage du message de chargement
    if ($(".load").length)
        $(".load").html("").html(waiting_message);
    else
        $(this).after("<div class=\"load\">" + waiting_message + "</div>");

    //Vérification du captcha
    if (!recap) {
        $.ajax({
            method: "POST",
            url: checkCaptchaUrl,
            data: "action=display_captcha_error",
            success: function (msg) {
                $(".load").html("");

                /* This doesn't work for me
                $(errorSelector).remove();
                //There's no #account-creation_form, but #opc_new_account
                $(formSelector).before(msg); 
                $("html, body").animate({scrollTop:$(errorSelector).offset().top  },"slow");
                */

                formSelector = $(".load");
                $(formSelector).html("<br>" + msg);

            }
        });

        //Optional: commented for keep processing
        //return false;
    }
    else {
        $(".load").html("");
    }
});
tucoinfo commented 5 years ago

I'm not getting results with any of these fixes. Maybe something to do with the response format (the error box doesn't update for example). Anyone else?

nenes25 commented 5 years ago

Hi,

Please see #100 , for a quick fix i've removed the captcha on the opc checkout page. A new relase will be publish once i've some confirmations that everything works well ;)

Regards,

tucoinfo commented 5 years ago

Looks good to me. Thanks again!