? Success

User tests: Successful: Unsuccessful:

avatar 810
810
9 Jan 2016

Issue

Now you can't have multiple recaptcha's on a single page. Also 3rt party support doesn't work correct.

How To Reproduce

1) Install Kunena, enable recaptcha on joomla and kunena, also setup category correct, and enable public write option on kunena config.
also set option captcha for guests and users

2) Create a new topic on kunena, or reply topic.
3) You will not see any recaptcha

After Fix

You see recaptcha on new topic, also you can now have multiple recapcha's. like one a topic with multiple replies.

avatar 810 810 - open - 9 Jan 2016
avatar 810 810 - change - 9 Jan 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 9 Jan 2016
Labels Added: ?
avatar rich20
rich20 - comment - 9 Jan 2016

Works with his fix.

avatar Fedik
Fedik - comment - 9 Jan 2016

in theory, this should be fixed already, by #8191

btw, current code breaks changes that made in #8191

avatar 810
810 - comment - 9 Jan 2016

when we do this: https://github.com/Kunena/Kunena-Forum/blob/develop/components/com_kunena/site/controller/topic/form/create/display.php#L81

Its not working anymore on J3.5, on J3.4 its working correct.
What i see on the code, its just loading the js, nothing else.

avatar Fedik
Fedik - comment - 9 Jan 2016

hm, strange ... and even at least one reCAPTCHA did not displayed?

What i see on the code, its just loading the js, nothing else.

it actually do "Automatically render the reCAPTCHA widget" https://developers.google.com/recaptcha/docs/display

avatar Fedik
Fedik - comment - 9 Jan 2016

@810 I do not see you call onDisplay in your link

avatar 810
810 - comment - 9 Jan 2016

@Fedik we don't use ondispaly we use this: https://github.com/Kunena/Kunena-Forum/blob/develop/components/com_kunena/site/template/crypsis/layouts/message/edit/quickreply.php#L122

only the jquery isn't added to the html:
jQuery(document).ready(function($) {$(window).load(function() {grecaptcha.render("dynamic_recaptcha_1", {sitekey: "6LeoGscSAAAAAE8OqeBj4_foU-pfRNK4xmjMxyiu", theme: "clean"});});});

avatar Fedik
Fedik - comment - 9 Jan 2016

we don't use ondispaly

that the reason of:

Its not working anymore on J3.5, on J3.4 its working correct.

No one can guarantee that all will work if you use Joomla Captcha API incorrect :wink:

you just need to render result of onDispaly there https://github.com/Kunena/Kunena-Forum/blob/develop/components/com_kunena/site/template/crypsis/layouts/message/edit/quickreply.php#L122

avatar xillibit
xillibit - comment - 4 Feb 2016

From what i understand under J3.5, you have choosed the easiest method which is able to load only one captcha in the page and not multiple captcha.

avatar 810
810 - comment - 11 Feb 2016

@Fedik ok, i have updated our code, but it isn't working. Only first message is showed. But the other id are correct, so the js is still wrong.

avatar Fedik
Fedik - comment - 11 Feb 2016

hm, yes you are right, multiple reCaptcha does not work,
but suggested changes is too "old school" :smile:
I have other idea, but need wait for weekend ....

avatar andrepereiradasilva
andrepereiradasilva - comment - 12 Feb 2016

@Fedik, google recaptcha API seems to not support loading multiple recaptcha with render=onload method. The explicit method (render=explicit) with a onload callback (onload=xxxxxxx) is need for that.

So, just as a PoC, how about replacing this line (https://github.com/joomla/joomla-cms/blob/staging/plugins/captcha/recaptcha/recaptcha.php#L60) for something like this:

JHtml::_('script', 'system/captcha.js', false, true);
$file = 'https://www.google.com/recaptcha/api.js?onload=onLoadCaptcha&render=explicit&hl=' . JFactory::getLanguage()->getTag();

And then create a js file "captcha.js" in "/media/system/js/" with this content:

// IE 8 compatibility
if (typeof Array.prototype.forEach != "function") {
    Array.prototype.forEach = function(callback){
      for (var i = 0; i < this.length; i++){
        callback.apply(this, [this[i], i, this]);
      }
    };
}

// Onload captcha event
window.onLoadCaptcha = function()
{
    Array.prototype.forEach.call(document.getElementsByClassName("g-recaptcha"), function(element, index, array)
    {
        grecaptcha.render(element.getAttribute("id"),
        {
            "sitekey": element.getAttribute("data-sitekey"),
            "theme": element.getAttribute("data-theme"),
            "size": element.getAttribute("data-size")
        });
    });
}

@810, would something like this work?

avatar Fedik
Fedik - comment - 12 Feb 2016

@andrepereiradasilva yes, something like this will work, but there still a way to optimize it :smile:

avatar andrepereiradasilva
andrepereiradasilva - comment - 12 Feb 2016

Sure :). Will wait for your PR and will test it.

avatar N6REJ
N6REJ - comment - 12 Feb 2016

why do we care about IE8?
Bear

On 2/12/2016 07:05, andrepereiradasilva wrote:

@Fedik https://github.com/Fedik, google recaptcha API seems to not
support loading multiple recaptcha with render=onload method. The
explicit method (render=explicit) with a onload callback
(onload=xxxxxxx) is need for that.

So, just as a PoC, how about replacing this line
(https://github.com/joomla/joomla-cms/blob/staging/plugins/captcha/recaptcha/recaptcha.php#L60)
for something like this:

JHtml::_('script', 'system/captcha.js', false, true);
$file =
'https://www.google.com/recaptcha/api.js?onload=onLoadCaptcha&amp;render=explicit&amp;hl='
. JFactory::getLanguage()->getTag();

And then create a js file "captcha.js" in "/media/system/js/" with
this content:

// IE 8 compatibility
if (typeof Array.prototype.forEach != "function") {
Array.prototype.forEach = function(callback){
for (var i= 0; i< this.length; i++){
callback.apply(this, [this[i], i,this]);
}
};
}

// Onload captcha event
window.onLoadCaptcha = function()
{
Array.prototype.forEach.call(document.getElementsByClassName("g-recaptcha"),function(element,index,array)
{
grecaptcha.render(element.getAttribute("id"),
{
"sitekey": element.getAttribute("data-sitekey"),
"theme": element.getAttribute("data-theme"),
"size": element.getAttribute("data-size")
});
});
}

@810 https://github.com/810, would something like this work?


Reply to this email directly or view it on GitHub
#8867 (comment).

avatar andrepereiradasilva
andrepereiradasilva - comment - 12 Feb 2016
avatar 810
810 - comment - 12 Feb 2016

Ok, i tested this:

JHtml::_('script', 'captcha.js', false, true);
$file = 'https://www.google.com/recaptcha/api.js?onload=onLoadCaptcha&render=explicit&hl=' . JFactory::getLanguage()->getTag();

and:

 // IE 8 compatibility
if (typeof Array.prototype.forEach != "function") {
    Array.prototype.forEach = function(callback){
        for (var i = 0; i < this.length; i++){
            callback.apply(this, [this[i], i, this]);
        }
    };
}

// Onload captcha event
window.onLoadCaptcha = function()
{
    Array.prototype.forEach.call(document.getElementsByClassName("g-recaptcha"), function(element, index, array)
    {
        grecaptcha.render(element.getAttribute("id"),
            {
                "sitekey": element.getAttribute("data-sitekey"),
                "theme": element.getAttribute("data-theme"),
                "size": element.getAttribute("data-size")
            });
    });
};

But i get: Verification expired. Check the checkbox again.

avatar andrepereiradasilva
andrepereiradasilva - comment - 12 Feb 2016

ok. let's wait for Fedik PR

avatar Fedik
Fedik - comment - 12 Feb 2016

@810 please test #9111

avatar andrepereiradasilva
andrepereiradasilva - comment - 13 Feb 2016

i think this PR can be closed now.

avatar brianteeman
brianteeman - comment - 16 Feb 2016

Closing in favour of #9111

avatar brianteeman brianteeman - change - 16 Feb 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-02-16 18:17:45
Closed_By brianteeman
avatar brianteeman brianteeman - close - 16 Feb 2016

Add a Comment

Login with GitHub to post a comment