Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23ec26d

Browse files
Update recaptcha_v2_verification.pl
1 parent 61ad03c commit 23ec26d

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

‎web_programming/recaptcha_verification/recaptcha_v2_verification.pl

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@
2222
# Add your 'Secret Key' here
2323
$ENV{'CAPTCHA_V2_SECRET_KEY'} = "";
2424

25-
sub is_valid_captcha {
26-
my ($c) = @_;
25+
# https://docs.mojolicious.org/Mojolicious/Lite#Helpers
26+
# Check for authentication
27+
helper auth => sub {
28+
my $c = shift;
29+
30+
if (($c->param('username') eq 'admin') && ($c->param('password') eq 'admin')) {
31+
return 1;
32+
}
33+
else {
34+
return 0;
35+
}
36+
};
37+
38+
helper verify_captcha => sub {
39+
my $c = shift;
2740
my $param = $c->param('g-recaptcha-response');
2841

2942
my $captcha_url = 'https://www.google.com/recaptcha/api/siteverify';
@@ -44,29 +57,6 @@ sub is_valid_captcha {
4457
# Connection to reCAPTCHA failed
4558
return 0;
4659
}
47-
}
48-
49-
# https://docs.mojolicious.org/Mojolicious/Lite#Helpers
50-
# Check for authentication
51-
helper auth => sub {
52-
my $c = shift;
53-
54-
if (($c->param('username') eq 'admin') && ($c->param('password') eq 'admin')) {
55-
return 1;
56-
}
57-
else {
58-
return 0;
59-
}
60-
};
61-
62-
helper verify_captcha => sub {
63-
my $c = shift;
64-
if (is_valid_captcha($c)) {
65-
return 1;
66-
}
67-
else {
68-
return 0;
69-
}
7060
};
7161

7262
helper ua => sub {
@@ -104,9 +94,13 @@ sub is_valid_captcha {
10494
# https://docs.mojolicious.org/Mojolicious/Lite#Under
10595
under sub {
10696
my $c = shift;
107-
return 1 if ($c->session('auth') // '') eq '1';
97+
my $auth = $c->session('auth') // '';
98+
if ($auth eq '1') {
99+
return 1;
100+
}
108101

109-
$c->render('denied');
102+
$c->render(template => 'denied');
103+
return undef;
110104
};
111105

112106
get '/home' => sub {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /