Catalyst::TraitFor::Controller::reCAPTCHA - authenticate people and read books!
version 1.112814
In your controller
package MyApp::Controller::Comment; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller' } with 'Catalyst::TraitFor::Controller::reCAPTCHA'; sub example : Local { my ( $self, $c ) = @; # validate received form if ( $c->forward('captcha_check') ) { $c->detach('my_form_is_ok'); } # Set reCAPTCHA html code $c->forward('captcha_get'); } 1;
Catalyst::Controller role around Capatcha::reCAPTCHA. Provides a number of Private methods that deal with the recaptcha.
Private
This module is based/copied from Catalyst::Controller::reCAPTCHA, it just adds support for option passing and automatically sets ssl when used on a secure request.
If you are using Catalyst::Controller::reCAPTCHA and want to move to this role, you only need to stop extending Catalyst::Controller and apply this role as shown in the SYNOPSIS.
In MyApp.pm (or equivalent in config file):
__PACKAGE__->config->{recaptcha} = { pub_key => '6LcsbAAAAAAAAPDSlBaVGXjMo1kJHwUiHzO2TDze', priv_key => '6LcsbAAAAAAAANQQGqwsnkrTd7QTGRBKQQZwBH-L', options => { theme => 'white' } };
(the two keys above work for http://localhost unless someone hammers the reCAPTCHA server with failures, in which case the API keys get a temporary ban).
captcha_get : Private
Sets $c->stash->{recaptcha} to be the html form for the http://recaptcha.net/ reCAPTCHA service which can be included in your HTML form.
captcha_check : Private
Validates the reCaptcha using Captcha::reCAPTCHA. sets $c->stash->{recaptcha_ok} which will be 1 on success. The action also returns true if there is success. This means you can do:
if ( $c->forward(captcha_check) ) { # do something based on the reCAPTCHA passing }
or alternatively:
$c->forward(captcha_check); if ( $c->stash->{recaptcha_ok} ) { # do something based on the reCAPTCHA passing }
If there's an error, $c->stash->{recaptcha_error} is set with the error string provided by Captcha::reCAPTCHA.
Captcha::reCAPTCHA
Catalyst::Controller
Catalyst
This module is almost copied from Kieren Diment Catalyst::Controller::reCAPTCHA.
Diego Kuperman <diego@freekeylabs.com>
This software is copyright (c) 2011 by Diego Kuperman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::TraitFor::Controller::reCAPTCHA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::TraitFor::Controller::reCAPTCHA
CPAN shell
perl -MCPAN -e shell install Catalyst::TraitFor::Controller::reCAPTCHA
For more information on module installation, please visit the detailed CPAN module installation guide.