The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::TraitFor::Controller::reCAPTCHA - authenticate people and read books!

VERSION

version 1.122510

SYNOPSIS

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;

SUMMARY

Catalyst::Controller role around Captcha::reCAPTCHA. Provides a number of Private methods that deal with the recaptcha.

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.

CONFIGURATION

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).

METHODS

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.

SEE ALSO

ACKNOWLEDGEMENTS

This module is almost copied from Kieren Diment Catalyst::Controller::reCAPTCHA.

AUTHOR

Diego Kuperman <diego@freekeylabs.com>

COPYRIGHT AND LICENSE

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.