Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Konfigurácia v Vytvorenie reCaptcha účtu:

https://www.google.com/recaptcha

  • v doménach je potrebné nastaviť všetky domény, ktoré budú reCaptcha overovanie zobrazovať
  • v nastaveniach novovytvoreného účtu sú 2 hashe - site key a private key - obidva je potrebné dať do konfigurácie webu, ideálne do master.conf:
Code Block
languageperl
$tom::setup{'recaptcha'}{'site'} = "asASJkaj4...aaw4";
$tom::setup{'recaptcha'}{'secret'} = "234asd...asdasd3";

...

Code Block
languagexml
            <script src='https://www.google.com/recaptcha/api.js?hl=[% lng %]'></script>
            <form action="?|?|" method="post" id="zem_spieva_signup_form" accept-charset="utf-8">
				<div class="g-recaptcha" data-sitekey="[% domain.setup.recaptcha.site %]" data-tabindes="9"></div>
				<input type="submit" value="Send" />
			</form>

 

Implementácia v module:

Code Block
languageperl
            my $recaptcha_success = 1;
			
            eval {
                use JSON;
                use LWP::UserAgent;
                
                my $ua = LWP::UserAgent->new;
                
                my $tmp = $ua->post(
                    'https://www.google.com/recaptcha/api/siteverify',
                    {
                        'secret' => $tom::setup{'recaptcha'}{'secret'},
                        'response' => $main::FORM{'g-recaptcha-response'}
                    }
                );
                
                my $result = from_json($tmp->decoded_content);
                
                main::_log(' recaptcha success value: '.$result->{'success'});
                
                if($result->{'success'} ne 'true')
                {
                    $recaptcha_success = 0;
                }
            };
            
            if ($@)
            {
                main::_log("recaptcha validation problem ".$@, 1);
            }
            
            if ($recaptcha_success)
            {
				...
			}
$main::FORM{'g-recaptcha-response'} je pevný názov poľa vo formulári, generovaný reCaptcha skriptom.