line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Qaptcha; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
24902
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
4
|
|
|
|
|
11046
|
|
|
4
|
|
|
|
|
28
|
|
4
|
4
|
|
|
4
|
|
2523
|
use FindBin qw'$Bin'; |
|
4
|
|
|
|
|
1086
|
|
|
4
|
|
|
|
|
482
|
|
5
|
4
|
|
|
4
|
|
1079
|
use Mojo::Util 'slurp'; |
|
4
|
|
|
|
|
57225
|
|
|
4
|
|
|
|
|
301
|
|
6
|
4
|
|
|
4
|
|
60
|
use File::Basename 'dirname'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
202
|
|
7
|
4
|
|
|
4
|
|
21
|
use File::Spec; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
93
|
|
8
|
4
|
|
|
4
|
|
3265
|
use File::ShareDir; |
|
4
|
|
|
|
|
24212
|
|
|
4
|
|
|
|
|
3794
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
3
|
|
|
3
|
1
|
142
|
my ($self, $app, $config) = @_; |
14
|
3
|
|
|
|
|
33
|
$app->config->{$_} = $config->{$_} for keys %$config; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
100
|
|
|
127
|
$app->config->{qaptcha_url} ||= q|/qaptcha|; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
63
|
$app->helper(qaptcha_include => \&_qaptcha_include); |
19
|
3
|
|
|
|
|
120
|
$app->helper(qaptcha_is_unlocked => \&_is_unlocked); |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
101
|
my $r = $app->routes; |
22
|
|
|
|
|
|
|
$r->route($app->config->{qaptcha_url})->to( |
23
|
|
|
|
|
|
|
cb => sub { |
24
|
2
|
|
|
2
|
|
67032
|
my $self = shift; |
25
|
2
|
|
|
|
|
6
|
my $aResponse = {}; |
26
|
2
|
|
|
|
|
7
|
$aResponse->{error} = 0; |
27
|
|
|
|
|
|
|
|
28
|
2
|
50
|
33
|
|
|
13
|
if ($self->param('action') && $self->param('qaptcha_key')) { |
29
|
2
|
|
|
|
|
864
|
$self->session('qaptcha_key', undef); |
30
|
2
|
50
|
|
|
|
906
|
if ($self->param('action') eq 'qaptcha') { |
31
|
2
|
|
|
|
|
123
|
$self->session('qaptcha_key', $self->param('qaptcha_key')); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
0
|
$aResponse->{error} = 1; |
35
|
|
|
|
|
|
|
} |
36
|
2
|
|
|
|
|
153
|
return $self->render(json => $aResponse); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
|
|
|
|
0
|
$aResponse->{error} = 1; |
40
|
0
|
|
|
|
|
0
|
return $self->render(json => $aResponse); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
3
|
|
|
|
|
25
|
); |
44
|
|
|
|
|
|
|
$r->route('/images/bg_draggable_qaptcha.jpg')->to( |
45
|
|
|
|
|
|
|
cb => sub { |
46
|
1
|
|
|
1
|
|
35676
|
my $self = shift; |
47
|
1
|
|
|
|
|
6
|
$self->render( |
48
|
|
|
|
|
|
|
data => slurp(&_basedir . "/bg_draggable_qaptcha.jpg"), |
49
|
|
|
|
|
|
|
format => 'jpg' |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
3
|
|
|
|
|
971
|
); |
53
|
|
|
|
|
|
|
$app->hook( |
54
|
|
|
|
|
|
|
after_dispatch => sub { |
55
|
12
|
|
|
12
|
|
56408
|
my $c = shift; |
56
|
|
|
|
|
|
|
$c->session('qaptcha_key', '') |
57
|
12
|
100
|
|
|
|
52
|
if $c->req->url->path->to_string ne $app->config->{qaptcha_url}; |
58
|
|
|
|
|
|
|
} |
59
|
3
|
|
|
|
|
1130
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _qaptcha_include { |
63
|
9
|
|
|
9
|
|
33496
|
my $c = shift; |
64
|
9
|
|
|
|
|
16
|
my $url_base = shift; |
65
|
|
|
|
|
|
|
|
66
|
9
|
|
|
|
|
35
|
my $cfg = $c->app->config; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $jquery = $cfg->{inbuild_jquery} |
69
|
9
|
100
|
66
|
|
|
225
|
&& $cfg->{inbuild_jquery} == 1 ? slurp(&_basedir . "/jquery.js") : ''; |
70
|
|
|
|
|
|
|
my $jquery_ui |
71
|
9
|
100
|
66
|
|
|
2413
|
= $cfg->{inbuild_jquery_ui} && $cfg->{inbuild_jquery_ui} == 1 |
72
|
|
|
|
|
|
|
? slurp(&_basedir . "/jquery-ui.js") |
73
|
|
|
|
|
|
|
: ''; |
74
|
|
|
|
|
|
|
my $jquery_ui_touch |
75
|
9
|
100
|
66
|
|
|
1359
|
= $cfg->{inbuild_jquery_ui_touch} && $cfg->{inbuild_jquery_ui_touch} == 1 |
76
|
|
|
|
|
|
|
? slurp(&_basedir . "/jquery.ui.touch.js") |
77
|
|
|
|
|
|
|
: ''; |
78
|
9
|
|
|
|
|
561
|
my $qaptcha_js = slurp(&_basedir . "/QapTcha.jquery.js"); |
79
|
9
|
|
|
|
|
638
|
my $qaptcha_css = slurp(&_basedir . "/QapTcha.jquery.css"); |
80
|
|
|
|
|
|
|
|
81
|
9
|
|
100
|
|
|
581
|
$cfg->{txtLock} ||= q|Locked : form can't be submited|; |
82
|
9
|
|
100
|
|
|
58
|
$cfg->{txtUnlock} ||= q|Unlocked : form can be submited|; |
83
|
9
|
|
100
|
|
|
38
|
$cfg->{disabledSubmit} ||= q|false|; |
84
|
9
|
|
100
|
|
|
33
|
$cfg->{autoRevert} ||= q|true|; |
85
|
9
|
|
100
|
|
|
28
|
$cfg->{autoSubmit} ||= q|false|; |
86
|
|
|
|
|
|
|
|
87
|
9
|
|
|
|
|
82
|
require Mojo::DOM; |
88
|
9
|
|
|
|
|
2408
|
my $script = <
|
89
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
EOS |
107
|
9
|
|
|
|
|
95
|
my $dom = Mojo::DOM->new($script); |
108
|
9
|
|
|
|
|
7609
|
$dom->xml(1); |
109
|
|
|
|
|
|
|
|
110
|
9
|
|
|
|
|
181
|
require Mojo::ByteStream; |
111
|
9
|
|
|
|
|
45
|
return Mojo::ByteStream->new($dom->to_string); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _is_unlocked { |
115
|
7
|
|
|
7
|
|
44327
|
my $self = shift; |
116
|
7
|
100
|
|
|
|
35
|
if ($self->session('qaptcha_key')) { |
117
|
4
|
|
|
4
|
|
28
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
787
|
|
118
|
2
|
50
|
|
|
|
797
|
if ($self->req->param($self->session('qaptcha_key')) eq '') { |
119
|
2
|
|
|
|
|
588
|
return 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
5
|
|
|
|
|
1983
|
return 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _basedir { |
126
|
43
|
|
33
|
43
|
|
1713
|
my $dir |
127
|
|
|
|
|
|
|
= File::Spec->catdir( |
128
|
|
|
|
|
|
|
dirname(__FILE__) . "/../../../jquery" // |
129
|
|
|
|
|
|
|
File::ShareDir::dist_dir('Mojolicious-Plugin-Qaptcha')); |
130
|
43
|
|
|
|
|
219
|
return $dir; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Mojolicious::Plugin::Qaptcha - jQuery QapTcha Plugin for Mojolicious |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Mojolicious |
140
|
|
|
|
|
|
|
$app->plugin('Qaptcha', { |
141
|
|
|
|
|
|
|
inbuild_jquery => 1, |
142
|
|
|
|
|
|
|
inbuild_jquery_ui => 1, |
143
|
|
|
|
|
|
|
inbuild_jquery_ui_touch => 1, |
144
|
|
|
|
|
|
|
txtLock => "LOCKED", |
145
|
|
|
|
|
|
|
txtUnlock => "UNLOCKED", |
146
|
|
|
|
|
|
|
disabledSubmit => "true", |
147
|
|
|
|
|
|
|
autoRevert => "false", |
148
|
|
|
|
|
|
|
autoSubmit => "true", |
149
|
|
|
|
|
|
|
qaptcha_url => '/do_unlock', |
150
|
|
|
|
|
|
|
}); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Mojolicious::Lite |
153
|
|
|
|
|
|
|
plugin 'Qaptcha', { |
154
|
|
|
|
|
|
|
inbuild_jquery => 1, |
155
|
|
|
|
|
|
|
inbuild_jquery_ui => 1, |
156
|
|
|
|
|
|
|
inbuild_jquery_ui_touch => 1, |
157
|
|
|
|
|
|
|
txtLock => "LOCKED", |
158
|
|
|
|
|
|
|
txtUnlock => "UNLOCKED", |
159
|
|
|
|
|
|
|
disabledSubmit => "true", |
160
|
|
|
|
|
|
|
autoRevert => "false", |
161
|
|
|
|
|
|
|
autoSubmit => "true", |
162
|
|
|
|
|
|
|
qaptcha_url => '/do_unlock', |
163
|
|
|
|
|
|
|
}; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
and in your templates |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
@@ layouts/default.html.ep |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
%= qaptcha_include |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
%= content; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
@@ index.html.ep |
179
|
|
|
|
|
|
|
%= layout 'default'; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
and in your controller |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Mojolicious::Lite |
195
|
|
|
|
|
|
|
any '/' => sub { |
196
|
|
|
|
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
do_something if $self->qaptcha_is_unlocked; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$self->render('index'); |
201
|
|
|
|
|
|
|
}; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Mojolicious |
204
|
|
|
|
|
|
|
sub index { |
205
|
|
|
|
|
|
|
my $self = shift; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
do_something if $self->qaptcha_is_unlocked; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$self->render('index'); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 DESCRIPTION |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L is a L plugin. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
It brings jQuery QapTcha functionality inside your html form |
217
|
|
|
|
|
|
|
in an element with class 'QapTcha'. |
218
|
|
|
|
|
|
|
When QapTcha is unlocked, next request has to |
219
|
|
|
|
|
|
|
submit form. Otherwise QapTcha will be locked back. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 METHODS |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L inherits all methods from |
224
|
|
|
|
|
|
|
L and implements the following new ones. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 register |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new, $options_hash); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Register plugin in L application. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 HELPERS |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=over 4 |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item qaptcha_include |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Includes (optional configured) jquery and qaptcha javascript. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item qaptcha_is_unlocked |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Returns 1 if QapTcha is unlocked. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=back |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 OPTIONS |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=over 4 |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item inbuild_jquery |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
If set to 1 jQuery 1.8.2 is rendered into %= qaptcha_include. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item inbuild_jquery_ui |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
If set to 1 jQuery UI - v1.8.2 is rendered into %= qaptcha_include. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item inbuild_jquery_ui_touch |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
If set to 1 jQuery.UI.iPad plugin is rendered into %= qaptcha_include. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item txtLock |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Text to display for locked QapTcha |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item txtUnlock |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Text to display for unlocked QapTcha |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item disabledSubmit |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Add the "disabled" attribut to the submit button |
274
|
|
|
|
|
|
|
default: false |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=item autoRevert |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Slider returns to the init-position, when the user hasn't dragged it to end |
279
|
|
|
|
|
|
|
default: true |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item autoSubmit |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
If true, auto-submit form when the user has dragged it to the end |
284
|
|
|
|
|
|
|
default: false |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item qaptcha_url |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Configurable route to unlock qaptcha |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=back |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
an example is located in L. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head1 INSTALLATION |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
To install this module, run the following commands: |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
perl Build.PL |
299
|
|
|
|
|
|
|
./Build |
300
|
|
|
|
|
|
|
./Build test |
301
|
|
|
|
|
|
|
./Build install |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
SUPPORT AND DOCUMENTATION |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
After installing, you can find documentation for this module with the |
306
|
|
|
|
|
|
|
perldoc command. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
perldoc Mojolicious::Plugin::Qaptcha |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
You can also look for information at: |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
AnnoCPAN, Annotated CPAN documentation |
313
|
|
|
|
|
|
|
http://annocpan.org/dist/Mojolicious-Plugin-Qaptcha |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
CPAN Ratings |
316
|
|
|
|
|
|
|
http://cpanratings.perl.org/d/Mojolicious-Plugin-Qaptcha |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
Search CPAN |
319
|
|
|
|
|
|
|
http://search.cpan.org/dist/Mojolicious-Plugin-Qaptcha/ |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 SOURCE REPOSITORY |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
L |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 AUTHOR |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Holger Rupprecht - C |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head1 SEE ALSO |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
L, L, L. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
Copyright (C) 2013 by Holger Rupprecht |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
338
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=cut |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
1; |