File tree Expand file tree Collapse file tree 1 file changed +21
-27
lines changed
web_programming/recaptcha_verification Expand file tree Collapse file tree 1 file changed +21
-27
lines changed Original file line number Diff line number Diff line change 22
22
# Add your 'Secret Key' here
23
23
$ENV {' CAPTCHA_V2_SECRET_KEY' } = " " ;
24
24
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 ;
27
40
my $param = $c -> param(' g-recaptcha-response' );
28
41
29
42
my $captcha_url = ' https://www.google.com/recaptcha/api/siteverify' ;
@@ -44,29 +57,6 @@ sub is_valid_captcha {
44
57
# Connection to reCAPTCHA failed
45
58
return 0;
46
59
}
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
- }
70
60
};
71
61
72
62
helper ua => sub {
@@ -104,9 +94,13 @@ sub is_valid_captcha {
104
94
# https://docs.mojolicious.org/Mojolicious/Lite#Under
105
95
under sub {
106
96
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
+ }
108
101
109
- $c -> render(' denied' );
102
+ $c -> render(template => ' denied' );
103
+ return undef ;
110
104
};
111
105
112
106
get ' /home' => sub {
You can’t perform that action at this time.
0 commit comments