File: Captcha.pm

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package MyCatalystApp::Controller::Captcha;

use HTML::FormHandler;

use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

MyCatalystApp::Controller::Captcha - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    my $form = MyCatalystApp::Controller::Captcha::Form->new(
        ctx => $c,
    );

    if($form->process($c->req->params)){
        $c->res->body("verification succeeded");
    return;
    }
    $c->res->body($form->render);
}

=head2 test

returns the image belonging to the current captcha

=cut

sub image : Local {
    my ( $self, $c ) = @_;
    my $captcha = $c->session->{captcha};
    $c->response->body($captcha->{image});
    $c->response->content_type('image/'. $captcha->{type});
    $c->res->headers->expires( time() );
    $c->res->headers->header( 'Last-Modified' => HTTP::Date::time2str );
    $c->res->headers->header( 'Pragma'        => 'no-cache' );
    $c->res->headers->header( 'Cache-Control' => 'no-cache' );
}

sub get_rnd :Local{
    my ( $self, $c ) = @_;
    my $captcha = $c->session->{captcha};
    die "no captcha in session" unless $captcha;
    $c->res->body($captcha->{rnd});
}

=head1 AUTHOR

Lukas Thiemeier,1R/18,7289,none

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

{
    package MyCatalystApp::Controller::Captcha::Form;

    use HTML::FormHandler::Moose;
    extends qw/HTML::FormHandler/;
    with qw/
        HTML::FormHandler::Render::Simple
        HTML::FormHandler::TraitFor::Captcha
    /;

    has_field submit => ( type => "Submit" );

    __PACKAGE__->meta->make_immutable;
    1;
}

1;