| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Captcha::reCAPTCHA; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: use Captcha::reCAPTCHA in Mojolicious apps |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21023
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
34
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3121
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
1
|
|
|
|
|
654851
|
|
|
|
1
|
|
|
|
|
12
|
|
|
9
|
1
|
|
|
1
|
|
3438
|
use Mojo::ByteStream; |
|
|
1
|
|
|
|
|
821361
|
|
|
|
1
|
|
|
|
|
44
|
|
|
10
|
1
|
|
|
1
|
|
832
|
use Captcha::reCAPTCHA; |
|
|
1
|
|
|
|
|
112528
|
|
|
|
1
|
|
|
|
|
1371
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.05; |
|
13
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub register { |
|
16
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
17
|
0
|
|
|
|
|
|
my $app = shift; |
|
18
|
0
|
|
0
|
|
|
|
my $conf = shift || {}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$app->log->debug("Usage of Mojolicious::Plugin::Captcha::reCAPTCHA is deprecated; you should consider switching to Mojolicious::Plugin::ReCAPTCHAv2"); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
die ref($self), ": need private and public key\n" |
|
23
|
0
|
0
|
0
|
|
|
|
unless $conf->{private_key} and $conf->{public_key}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->attr( |
|
26
|
|
|
|
|
|
|
'recaptcha_obj' => sub { |
|
27
|
0
|
|
|
0
|
|
|
Captcha::reCAPTCHA->new; |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
0
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
|
|
$app->attr( recaptcha_private_key => sub { $conf->{private_key} } ); |
|
|
0
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
|
|
$app->attr( recaptcha_public_key => sub { $conf->{public_key} } ); |
|
|
0
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
|
|
$app->attr( recaptcha_use_ssl => sub { $conf->{use_ssl} } ); |
|
|
0
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
|
|
$app->attr( recaptcha_options => sub { $conf->{options} } ); |
|
|
0
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
|
|
$app->helper( recaptcha => sub { return shift->app->recaptcha_obj } ); |
|
|
0
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$app->helper( |
|
38
|
|
|
|
|
|
|
use_recaptcha => sub { |
|
39
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
40
|
0
|
|
|
|
|
|
$self->stash( recaptcha_html => $self->recaptcha_html(@_) ); |
|
41
|
0
|
|
|
|
|
|
return; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
$app->helper( |
|
45
|
|
|
|
|
|
|
recaptcha_html => sub { |
|
46
|
0
|
|
|
0
|
|
|
my ( $self, $err, $use_ssl, $options ) = @_; |
|
47
|
0
|
0
|
|
|
|
|
if ( !defined $use_ssl ) { |
|
48
|
0
|
0
|
0
|
|
|
|
if ( defined $self->app->recaptcha_use_ssl ) { |
|
|
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$use_ssl = $self->app->recaptcha_use_ssl; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
elsif ( $self->req->url->base->scheme eq 'https' |
|
52
|
|
|
|
|
|
|
or $self->req->headers->header('X-Forwarded-Protocol') eq 'https' ) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
0
|
|
|
|
|
|
$use_ssl = 1; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
else { |
|
57
|
0
|
|
|
|
|
|
$use_ssl = undef; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
0
|
|
|
|
|
if ( !defined $options ) { |
|
61
|
0
|
|
|
|
|
|
$options = $self->app->recaptcha_options; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
return Mojo::ByteStream->new( |
|
64
|
|
|
|
|
|
|
$self->recaptcha->get_html( $self->app->recaptcha_public_key, $err, $use_ssl, $options ) |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
$app->helper( |
|
69
|
|
|
|
|
|
|
validate_recaptcha => sub { |
|
70
|
0
|
|
|
0
|
|
|
my ( $self, $params ) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $result = $self->recaptcha->check_answer( $self->app->recaptcha_private_key, |
|
73
|
|
|
|
|
|
|
$self->tx->remote_address, |
|
74
|
|
|
|
|
|
|
$params->{recaptcha_challenge_field}, |
|
75
|
|
|
|
|
|
|
$params->{recaptcha_response_field}, |
|
76
|
0
|
|
|
|
|
|
); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ( !$result->{is_valid} ) { |
|
79
|
0
|
|
|
|
|
|
$self->stash( recaptcha_error => $result->{error} ); |
|
80
|
0
|
|
|
|
|
|
return 0; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
|
|
|
|
|
return 1; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
0
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return; |
|
87
|
|
|
|
|
|
|
} ## end sub register |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |