Im trying to apply google recaptcha at Customer Login form. Unfortunately, not properly working..im still have to rack my brain
However its working well when applied to Sign Up form instead.
Simulation :
- If captcha is empty, error throw --> working
- if captcha is right, while username/password wrong, error --> working
- if captcha is right, with correct username/password --> the page refresh, then still on the Login page.
However i can see the session is register in the system.
Code as below:
1. CustomerLogin.tt
Code: Select all
<!-- begin recaptcha -->
<div>
[% Data.reCAPTCHA %]
</div>
<!-- end recaptcha -->
<div>
<button type="submit" value="[% Translate("Log In") | html %]" disabled="disabled">[% Translate("Log In") | html %]</button>
</div>
Code: Select all
#begin recaptcha
use Captcha::reCAPTCHA::V2;
#end recaptcha
--------
--------
#begin recaptcha within CustomerLogin block
my $SiteKey2 = $ConfigObject->Get('GoogleCaptcha::SiteKey');
my $rc2 = Captcha::reCAPTCHA::V2->new;
$Param{reCAPTCHA} = $rc2->html($SiteKey2, { theme => 'dark' }, { size => 'compact' }); #public key
$Self->Block(
Name => 'Captcha',
Data => \%Param,
);
#end recaptcha
$Self->Block(
Name => 'LoginBox',
Data => \%Param,
);
Code: Select all
#begin recaptcha
use Captcha::reCAPTCHA::V2;
#end recaptcha
-----
-----
my $PostTwoFactorToken = $ParamObject->GetParam(
Param => 'TwoFactorToken',
Raw => 1
) || '';
#begin recaptcha
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $rc2 = Captcha::reCAPTCHA::V2->new;
my $SecretKey2 = $ConfigObject->Get('GoogleCaptcha::SecretKey');
my $response2 = $ParamObject->GetParam(Param => 'g-recaptcha-response') || '';
my $result2 = $rc2->verify($SecretKey2, $response2);
if ( !$result2->{success} )
{
#my $c_error = $result->{error_codes}->[0];
# show need user data error message
$LayoutObject->Print(
Output => \$LayoutObject->CustomerLogin(
Title => 'Error',
Message => Translatable(
'reCAPTCHA entry failed. Please try again.'
),
),
);
return;
}
#end recaptcha
# create AuthObject
my $AuthObject = $Kernel::OM->Get('Kernel::System::CustomerAuth');
Thanks