Dancer2::Plugin::reCAPTCHA - Integrate reCAPTCHA into Dancer2 applications
version 0.3
Dancer2::Plugin::reCAPTCHA allows you to easily use reCAPTCHA in Dancer2 applications.
Add the plugin to your application:
use Dancer2::Plugin::reCAPTCHA;
Configure its settings in the YAML configuration file:
plugins:
reCAPTCHA:
site_key: "site key"
secret: "secret key"
options:
theme: "light"
type: "image"
size: "normal"
Put reCAPTCHA in a template:
[% recaptcha %]
Display it:
return template 'feedback', {
recaptcha => recaptcha_display()
};
Validate user input in a route handler:
my $response = param('g-recaptcha-response');
my $result = recaptcha_verify($response);
if ($result->{success}) {
# Good
}
else {
# Bad
}
The available configuration settings are described below.
The reCAPTCHA site key.
The reCAPTCHA secret key.
Configuration to design the widget's apperance and behavior with these following keys:
theme
-
The color theme of the of the widget. Possible values are
'dark'
and'light'
. type
-
The type of the reCAPTCHA to serve. Possible values are
'audio'
and'image'
. size
-
The size of the widget. Possible values are
'compact'
and'normal'
.
Generates the HTML to display the captcha which should be placed in a template.
Example:
# In route handler
template 'index' => {
recaptcha => recaptcha_display()
};
# In template
[% recaptcha %]
Validates the input provided by the user to check if it is a correct answer. Arguments:
$response
-
Response string retrieved from the submitted form field
g-recaptcha-response
.
Returns a reference to a hash containing two fields: success
and error_codes
.
Example:
my $response = param('g-recaptcha-response');
my $result = recaptcha_verify($response);
if ($result->{success}) {
print "You are a human!";
}
else {
print $result->{error_codes}->[0];
}
* Google reCAPTCHA API Reference
Based on Jason A. Crome's plugin for Dancer version 1 (Dancer::Plugin::reCAPTCHA).
Please report any bugs or feature requests through the issue tracker at https://github.com/Sidnet/p5-Dancer2-Plugin-reCAPTCHA/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/Sidnet/p5-Dancer2-Plugin-reCAPTCHA
git clone https://github.com/Sidnet/p5-Dancer2-Plugin-reCAPTCHA.git
Pattawan Kaewduangdee <[email protected]>
Michal Wojciechowski <[email protected]>
This software is copyright (c) 2015 by Pattawan Kaewduangdee.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.