Mojolicious-Plugin-ReCAPTCHAv2
view release on metacpan or search on metacpan
# fail: probably bot, but may also be a processing error
if ( @{$err} ) {
# processing failed, inspect error codes
foreach my $e ( @{$err} ) {
...
}
}
else {
# bot
...
}
}
# asynchronous
Mojo::IOLoop->delay(
sub {
my $delay = shift;
$c->recaptcha_verify( $delay->begin(0) );
},
sub {
my ( $delay, $captcha_verified, $err ) = @_;
if ( $captcha_verified ) {
# success: probably human
...
}
else {
# fail: probably bot, but may also be a processing error
if ( @{$err} ) {
# processing failed, inspect error codes
foreach my $e ( @{$err} ) {
...
}
}
else {
# bot
...
}
}
}
)->wait;
=head1 DESCRIPTION
L<Mojolicious::Plugin::ReCAPTCHAv2> allows you to protect your site against
automated interaction by (potentially malicious) robots.
This is accomplished by injecting a extra javascript widget in your forms
that requires human interaction. The interaction is evaluated on a server
(via AJAX) and a dynamic parameter is injected in your form.
When your users submit your form to your server you receive that parameter
and can verify it by sending it to the captcha servers in the background.
You should then stop further processing of the request you received if the
captcha did not validate.
Please note that this module currently does not support some advanced usage
models for the captcha like explicit rendering and AJAX callbacks.
Therefore a few options listed in the official Google docs are not listed
above.
If you would like to see support for this kind of functionality, please
get in touch with the author / maintainer of this module.
For a general overview of what a Captcha is and how the Google "No Captcha"
reCaptcha (v2) service works, please refer to the
L<official documentation|https://developers.google.com/recaptcha/>.
=head1 OPTIONS
The following params can be provided to the plugin on registration:
=over 4
=item C<sitekey>
=item C<secret>
=item C<api_timeout>
=item C<api_url>
=item C<size>
=item C<tabindex>
=item C<theme>
=item C<type>
=back
C<sitekey> and C<secret> are required parameters, while all others are
optional. The default values for the optional configuration params are shown
in the synopsis.
For the meaning of these please refer to L<https://developers.google.com/recaptcha/docs/display#config>.
=head1 METHODS
L<Mojolicious::Plugin::ReCAPTCHAv2> inherits all methods from L<Mojolicious::Plugin>
and implements no extra ones.
=head1 HELPERS
L<Mojolicious::Plugin::ReCAPTCHAv2> makes the following helpers available:
=head2 recaptcha_get_html
Returns a HTML fragment with the widget code; you will probably want to put
this in the stash, since it has to be inserted in your HTML form element
when processing the template.
=head2 recaptcha_verify( [ $callback ] )
Call this helper when receiving the request from your website after the user
( run in 1.274 second using v1.01-cache-2.11-cpan-5837b0d9d2c )