| 1 | package Catalyst::Controller::reCAPTCHA; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base 'Catalyst::Controller'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Captcha::reCAPTCHA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.8'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub captcha_get : Private { | ||||||||||||||||||||||||||
|
Subroutine
captcha_get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | my ($self, $c) = @_; | |||||||||||||||||||||||||||
| 12 | 1 | my $cap = Captcha::reCAPTCHA->new; | |||||||||||||||||||||||||||
| 13 | $c->stash->{recaptcha} = | ||||||||||||||||||||||||||||
| 14 | 1 | $cap->get_html($c->config->{recaptcha}->{pub_key}); | |||||||||||||||||||||||||||
| 15 | 1 | return; | |||||||||||||||||||||||||||
| 16 | 2 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub captcha_check : Private { | ||||||||||||||||||||||||||
|
Subroutine
captcha_check: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||
| 20 | 0 | my $cap = Captcha::reCAPTCHA->new; | |||||||||||||||||||||||||||
| 21 | 0 | my $challenge = $c->req->param('recaptcha_challenge_field'); | |||||||||||||||||||||||||||
| 22 | 0 | my $response = $c->req->param('recaptcha_response_field'); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | unless ( $response && $challenge ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response and $challenge
MC/DC0%0/2
$response and $challenge
$response
$challenge
Truth table0%0/3
A and B
A= $responseB= $challenge
| |||||||||||||||||||||||||||||
| 25 | $c->stash->{recaptcha_error} = | ||||||||||||||||||||||||||||
| 26 | 0 | 'User appears not to have submitted a recaptcha'; | |||||||||||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | my $key = $c->config->{recaptcha}->{priv_key} || | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | croak 'must set recaptcha priv_key in config'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$c->config->{'recaptcha'}{'priv_key'} || croak('must set recaptcha priv_key in config')
MC/DC0%0/1
$c->config->{'recaptcha'}{'priv_key'} || croak('must set recaptcha priv_key in config')
$c->config->{'recaptcha'}{'priv_key'}
Truth table0%0/2
A
A= $c->config->{'recaptcha'}{'priv_key'}
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | my $result = $cap->check_answer( | |||||||||||||||||||||||||||
| 34 | $key, | ||||||||||||||||||||||||||||
| 35 | $c->req->address, | ||||||||||||||||||||||||||||
| 36 | $challenge, | ||||||||||||||||||||||||||||
| 37 | $response, | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | croak 'Failed to get valid result from reCaptcha' | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | unless ref $result eq 'HASH' && exists $result->{is_valid}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $result eq "HASH" and exists $result->{"is_valid"}
MC/DC0%0/2
ref $result eq "HASH" and exists $result->{"is_valid"}
ref $result eq "HASH"
exists $result->{"is_valid"}
Truth table0%0/3
A and B
A= ref $result eq "HASH"B= exists $result->{"is_valid"}
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | $c->stash->{recaptcha_error} = $result->{error} || | ||||||||||||||||||||||||||||
| 45 | 'Unknown error' | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless $result->{is_valid}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$result->{'error'} || 'Unknown error'
MC/DC0%0/1
$result->{'error'} || 'Unknown error'
$result->{'error'}
Truth table0%0/2
A
A= $result->{'error'}
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $c->stash->{recaptcha_ok} = 1 if $result->{is_valid}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | return 1; | |||||||||||||||||||||||||||
| 50 | 2 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 NAME | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Catalyst::Controller::reCAPTCHA - authenticate people and read books! | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | WARNING: Deprecated. Please use L<Catalyst::TraitFor::Controller::reCAPTCHA> instead. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 SUMMARY | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | This module has been deprecated and has been replaced with | ||||||||||||||||||||||||||||
| 64 | L<Catalyst::TraitFor::Controller::reCAPTCHA>. Please do not use this for new | ||||||||||||||||||||||||||||
| 65 | projects. Version 0.8 is very likely the last to be released for this module. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Catalyst::Controller wrapper around L<Capatcha::reCAPTCHA>. Provides | ||||||||||||||||||||||||||||
| 68 | a number of C<Private> methods that deal with the recaptcha. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 CONFIGURATION | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | In MyApp.pm (or equivalent in config file): | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __PACKAGE__->config->{recaptcha}->{pub_key} = | ||||||||||||||||||||||||||||
| 75 | '6LcsbAAAAAAAAPDSlBaVGXjMo1kJHwUiHzO2TDze'; | ||||||||||||||||||||||||||||
| 76 | __PACKAGE__->config->{recaptcha}->{priv_key} = | ||||||||||||||||||||||||||||
| 77 | '6LcsbAAAAAAAANQQGqwsnkrTd7QTGRBKQQZwBH-L'; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | (the two keys above work for http://localhost unless someone hammers the | ||||||||||||||||||||||||||||
| 80 | reCAPTCHA server with failures, in which case the API keys get a temporary | ||||||||||||||||||||||||||||
| 81 | ban). | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 METHOD | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | captcha_get : Private | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Sets $c->stash->{recaptcha} to be the html form for the L<http://recaptcha.net/> reCAPTCHA service which can be included in your HTML form. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head2 METHOD | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | captcha_check : Private | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Validates the reCaptcha using L<Captcha::reCAPTCHA>. sets | ||||||||||||||||||||||||||||
| 94 | $c->stash->{recaptcha_ok} which will be 1 on success. The action also returns | ||||||||||||||||||||||||||||
| 95 | true if there is success. This means you can do: | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | if ( $c->forward(captcha_check) ) { | ||||||||||||||||||||||||||||
| 98 | # do something based on the reCAPTCHA passing | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | or alternatively: | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | if ( $c->stash->{recaptcha_ok} ) { | ||||||||||||||||||||||||||||
| 104 | # do something based on the reCAPTCHA passing | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | If there's an error, $c->stash->{recaptcha_error} is | ||||||||||||||||||||||||||||
| 109 | set with the error string provided by L<Captcha::reCAPTCHA>. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 EXAMPLES | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | See the t/lib/TestApp example in the | ||||||||||||||||||||||||||||
| 114 | L<Catalyst::Controller::reCAPTCHA> distribution. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head2 BUGS | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | This module is deprecated. Please report any bugs you find against | ||||||||||||||||||||||||||||
| 119 | L<Catalyst::TraitFor::Controller::reCAPTCHA>. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | L<Captcha::reCAPTCHA>, L<Catalyst::Controller>, L<Catalyst>. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 AUTHOR and Copyright | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Kieren Diment L<zarquon@cpan.org>. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 LICENCE | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 132 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | 1; | |||||||||||||||||||||||||||