| 1 | package Catalyst::TraitFor::Controller::reCAPTCHA; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: authenticate people and read books! | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Catalyst::TraitFor::Controller::reCAPTCHA::VERSION = '2.00'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use MooseX::MethodAttributes::Role; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Captcha::reCAPTCHA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | has recaptcha => ( is => 'ro', default => sub { Captcha::reCAPTCHA->new } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | sub captcha_get :Private { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
captcha_get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my $recaptcha; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | if (lc($c->config->{recaptcha}{version} || '') eq 'v2') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$c->config->{'recaptcha'}{'version'} || ''
MC/DC100%1/1
$c->config->{'recaptcha'}{'version'} || ''
$c->config->{'recaptcha'}{'version'}
Truth table100%2/2
A
A= $c->config->{'recaptcha'}{'version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | $recaptcha = $self->recaptcha->get_html_v2( | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | $c->config->{recaptcha}{pub_key}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | $c->config->{recaptcha}{options} | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $recaptcha = $self->recaptcha->get_html( | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $c->config->{recaptcha}{pub_key}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $c->stash->{recaptcha_error}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $c->req->secure, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $c->config->{recaptcha}{options} | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | $c->stash( recaptcha => $recaptcha ); | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub captcha_check :Private { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
captcha_check: called CC=9 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $challenge = $c->req->param('recaptcha_challenge_field'); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $response = $c->req->param('recaptcha_response_field'); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $response_v2 = $c->req->param('g-recaptcha-response'); | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | unless ( ($response && $challenge || $response_v2)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$response and $challenge or $response_v2
$response and $challenge
MC/DC0%0/3
$response and $challenge or $response_v2
$response
$challenge
$response_v2
Truth table20%1/5
A and B or C
A= $responseB= $challengeC= $response_v2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $c->stash->{recaptcha_error} = 'User appears not to have submitted a recaptcha'; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if (lc($c->config->{recaptcha}{version} || '') eq 'v2') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$c->config->{'recaptcha'}{'version'} || ''
MC/DC0%0/1
$c->config->{'recaptcha'}{'version'} || ''
$c->config->{'recaptcha'}{'version'}
Truth table50%1/2
A
A= $c->config->{'recaptcha'}{'version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = $c->req->secure; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | $res = $self->recaptcha->check_answer_v2( | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $c->config->{recaptcha}{priv_key}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $response_v2, | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | $c->req->address | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $res = $self->recaptcha->check_answer( | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $c->config->{recaptcha}{priv_key}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $c->req->address, | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | $challenge, | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $response | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | croak 'Failed to get valid result from reCaptcha' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | unless ref $res eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | unless ( $res->{is_valid} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | $c->stash( recaptcha_error => $res->{error} || 'Invalid recaptcha' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->{'error'} || 'Invalid recaptcha'
MC/DC0%0/1
$res->{'error'} || 'Invalid recaptcha'
$res->{'error'}
Truth table50%1/2
A
A= $res->{'error'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $c->stash( recaptcha_ok => $res->{is_valid} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | return $res->{is_valid}; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||