Mojolicious::Plugin::Captcha::reCAPTCHA - use Captcha::reCAPTCHA in Mojolicious apps
version 0.05
Provides a Captcha::reCAPTCHA object in your Mojolicious app.
use Mojolicious::Plugin::Captcha::reCAPTCHA; sub startup { my $self = shift; $self->plugin('Captcha::reCAPTCHA', { private_key => 'the_public_key', public_key => 'your_private_key', use_ssl => 1, options => { theme => 'white' }, }); }
private_key and public_key are mandatory, while use_ssl and options are optional. Unless you have a specific reason to set a certain global value for use_ssl you should probably just let the plugin decide when to use HTTPS requests.
private_key
public_key
use_ssl
options
In your mojolicious controller you can control everything by yourself by directly invoking the get_html() method of the Captcha::reCAPTCHA object:
get_html()
$self->stash( recaptcha_html => $self->recaptcha->get_html( $public_key [, $error [, $use_ssl [, $options ] ] ] ), );
Following the same pattern you can also directly invoke check_answer():
check_answer()
my $result = $self->recaptcha->check_answer( $private_key, $ip, $value_of_challenge_field, $value_of_response_field, );
Or you can use the new helpers.
Mojolicious::Plugin::Captcha::reCAPTCHA is deprecated and you should consider switching to Mojolicious::Plugin::ReCAPTCHAv2.
The latter one uses the newer v2 API of Googles reCAPTCHA service and also has no dependencies besides Mojolicious (and IO::Socket::SSL, which again is a dependency of Mojolicious itself).
A helper named 'recaptcha' is created that can be used to access the Captcha::reCAPTCHA object.
my $recaptcha_obj = $self->recaptcha;
This helper sets the key recaptcha_html in the stash and uses the HTML as the value.
recaptcha_html
$self->use_recaptcha;
It automatically uses the public key and the other configuration options you passed in when registering the plugin.
You may explicitly pass in values for error, use_ssl, and options. If you do, these params will take precedence over the configuration values. Pass undef for positional params you either don't want to set or where you don't want to override the config values:
error
undef
$self->use_recaptcha( undef, undef, { theme => 'red' } );
Unless explicitly passed in or set in the configuration, the correct value for use_ssl is automatically determined based on the current request (by looking at $self-\req-\>url-\>base-\>scheme>).
$self-\
This helper works like use_recaptcha but returns the HTML instead of setting a stash value. Also accepts the same params as use_recaptcha().
use_recaptcha
use_recaptcha()
Intended to be used in templates.
Handles the validation of the recaptcha. If an error occurs, the stash variable "recaptcha_error" is set.
$self->validate_recaptcha( $params );
$params is a hashref with parameters of the HTTP request. Returns "true" (1) if validation was successful and "false" (0) otherwise.
$params
Renee Baecker <module@renee-baecker.de>
Heiko Jansen <jansen@hbz-nrw.de>
This software is Copyright (c) 2012 by Hochschulbibliothekszentrum NRW (hbz).
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
This software is Copyright (c) 2015 by Hochschulbibliothekszentrum NRW (hbz).
To install Mojolicious::Plugin::Captcha::reCAPTCHA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Captcha::reCAPTCHA
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Captcha::reCAPTCHA
For more information on module installation, please visit the detailed CPAN module installation guide.