frazap has asked for the wisdom of the Perl Monks concerning the following question:
I keep having a warning and a failure when I post the data after using reCaptchaV2
Mojo::Transaction::success is DEPRECATED in favor of Mojo::Transaction +::result and Mojo::Transaction::error at C:/strawberry/perl/site/lib/ +Mojolicious/Plugin/ReCAPTCHAv2.pm line 100. Error code : missing-input-response
From the module page, it is suggested that the error would come from a mistake in the template.
My template is:I call the plugin in my startup sub%= form_for surv => (method => 'POST') => begin <ul class='form-style-1'> <li> %= label_for name => 'Full name:' %= text_field 'firstname', class=> 'field-divided', placeholder=>'Fir +st' %= text_field 'name', class=> 'field-divided', placeholder=>'Last' ..... %= label_for lang2 => 'Skill in a second national language:' %= select_field lang2 => [[Small => 'small'], [Standard => 'standard'] +, [Good => 'good', selected => 'selected']], class => 'field-select' </li> <li> <%= $captcha %> </li> <li> %= input_tag Send => 'Send', type => 'submit' </li> </ul> %end
And I check the captcha response in my controller post action.... use Mojolicious::Plugin::ReCAPTCHAv2; sub startup { .... $self->plugin('ReCAPTCHAv2', { sitekey => '...', secret => '....', }); ... }
What am I missing ?sub post { my $c = shift; my $app = $c->app; if ( $app->recaptcha_verify ) { my $p = $c->req->body_params->to_hash; #... test for missing data #build sql string and add the data $app->log->debug($sql); my $stm = $app->db1->prepare($sql) or die $app->db1->errst +r; $stm->execute() or die $stm->errstr; $app->stash( msg => "Data well received, thank you" ); } } else { if ( my $err = $app->recaptcha_get_errors ) { foreach my $e ( @{$err} ) { $app->log->debug( "Error code : " . $e ); } } else { $app->log->debug("Surv.pm: could be a bot here"); } } }
Beside, I find these capatcha tests annoying... too much clicks.
IMHO the old captcha version with letters was simpler. Is there a Mojolicious plugin for this ? is there another solution to prevent my table from being filled by students testing their programming skills ?
Thanks !
frazap
Edit: from the module code and Google documentation, I should post something with g-recaptcha-response
In the helper recaptcha_verify :I don't think I send anything like this...my %verify_params = ( remoteip => $c->tx->remote_address, response => ( $c->req->param('g-recaptcha-response') | +| '' ), secret => $plugin->conf->{'secret'}, );
edit2:
okay...
here is an example with Mojolicious::Lite that gives the same error. To try it you need to set up a kaptcha for your computer on the google site https://developers.google.com/recaptcha/
use Mojolicious::Lite; use DBI; use Mojolicious::Plugin::ReCAPTCHAv2; plugin 'ReCAPTCHAv2' => { sitekey => '... your value received from google', secret => '... idem', api_timeout => 120, }; get '/surv' => sub { my $c = shift; $c->stash( captcha => $c->app->recaptcha_get_html ); }; post '/surv' => sub { my $c = shift; my $app = $c->app; if ( $app->recaptcha_verify ) { $app->log->debug( "Hi there " . $c->param('first name') ); } else { if ( my $err = $app->recaptcha_get_errors ) { foreach my $e ( @{$err} ) { $app->log->debug( "Error code : " . $e ); } } else { $app->log->debug("could be a bot here"); } } }; app->start; __DATA__ @@ surv.html.ep %= form_for surv => (method => 'POST') => begin %= text_field 'first_name' <%= $captcha %> %= submit_button %en
edit3:
Another problem is that I should served the form over https and not http according to the doc on google's site.
That could be a reason why this is not working
I tried this config file{ hypnotoad => { listen => ['https://*:3000'] } }
Without success
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mojolicious::Plugin::ReCAPTCHAv2 : missing -input-response
by Anonymous Monk on May 27, 2019 at 01:25 UTC |