| 1 |
package MyCatalystApp::Controller::Captcha; |
| 2 |
|
| 3 |
use HTML::FormHandler; |
| 4 |
|
| 5 |
use Moose; |
| 6 |
use namespace::autoclean; |
| 7 |
|
| 8 |
BEGIN {extends 'Catalyst::Controller'; } |
| 9 |
|
| 10 |
=head1 NAME |
| 11 |
|
| 12 |
MyCatalystApp::Controller::Captcha - Catalyst Controller |
| 13 |
|
| 14 |
=head1 DESCRIPTION |
| 15 |
|
| 16 |
Catalyst Controller. |
| 17 |
|
| 18 |
=head1 METHODS |
| 19 |
|
| 20 |
=cut |
| 21 |
|
| 22 |
|
| 23 |
=head2 index |
| 24 |
|
| 25 |
=cut |
| 26 |
|
| 27 |
sub index :Path :Args(0) { |
| 28 |
my ( $self, $c ) = @_; |
| 29 |
|
| 30 |
my $form = MyCatalystApp::Controller::Captcha::Form->new( |
| 31 |
ctx => $c, |
| 32 |
); |
| 33 |
|
| 34 |
if($form->process($c->req->params)){ |
| 35 |
$c->res->body("verification succeeded"); |
| 36 |
return; |
| 37 |
} |
| 38 |
$c->res->body($form->render); |
| 39 |
} |
| 40 |
|
| 41 |
=head2 test |
| 42 |
|
| 43 |
returns the image belonging to the current captcha |
| 44 |
|
| 45 |
=cut |
| 46 |
|
| 47 |
sub image : Local { |
| 48 |
my ( $self, $c ) = @_; |
| 49 |
my $captcha = $c->session->{captcha}; |
| 50 |
$c->response->body($captcha->{image}); |
| 51 |
$c->response->content_type('image/'. $captcha->{type}); |
| 52 |
$c->res->headers->expires( time() ); |
| 53 |
$c->res->headers->header( 'Last-Modified' => HTTP::Date::time2str ); |
| 54 |
$c->res->headers->header( 'Pragma' => 'no-cache' ); |
| 55 |
$c->res->headers->header( 'Cache-Control' => 'no-cache' ); |
| 56 |
} |
| 57 |
|
| 58 |
sub get_rnd :Local{ |
| 59 |
my ( $self, $c ) = @_; |
| 60 |
my $captcha = $c->session->{captcha}; |
| 61 |
die "no captcha in session" unless $captcha; |
| 62 |
$c->res->body($captcha->{rnd}); |
| 63 |
} |
| 64 |
|
| 65 |
=head1 AUTHOR |
| 66 |
|
| 67 |
Lukas Thiemeier,1R/18,7289,none |
| 68 |
|
| 69 |
=head1 LICENSE |
| 70 |
|
| 71 |
This library is free software. You can redistribute it and/or modify |
| 72 |
it under the same terms as Perl itself. |
| 73 |
|
| 74 |
=cut |
| 75 |
|
| 76 |
__PACKAGE__->meta->make_immutable; |
| 77 |
|
| 78 |
{ |
| 79 |
package MyCatalystApp::Controller::Captcha::Form; |
| 80 |
|
| 81 |
use HTML::FormHandler::Moose; |
| 82 |
extends qw/HTML::FormHandler/; |
| 83 |
with qw/ |
| 84 |
HTML::FormHandler::Render::Simple |
| 85 |
HTML::FormHandler::TraitFor::Captcha |
| 86 |
/; |
| 87 |
|
| 88 |
has_field submit => ( type => "Submit" ); |
| 89 |
|
| 90 |
__PACKAGE__->meta->make_immutable; |
| 91 |
1; |
| 92 |
} |
| 93 |
|
| 94 |
1; |