source: trunk/lib/Vote/Controller/Ballot.pm @ 13

Last change on this file since 13 was 13, checked in by nanardon, 15 years ago
  • add authentication part
File size: 1.7 KB
Line 
1package Vote::Controller::Ballot;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7=head1 NAME
8
9Vote::Controller::Ballot - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index : Private {
25    my ( $self, $c ) = @_;
26
27    $c->response->body('Matched Vote::Controller::Ballot in Vote.');
28}
29
30sub default : Private {
31    my ( $self, $c, undef, $id ) = @_;
32
33    $c->stash->{voteid} = $id;
34
35    my $uid = $c->session->{uid} || $c->req->param('uid');
36    my $password = $c->session->{password} || $c->req->param('password');
37
38    if (!$c->model('Vote')->auth_voting($id, $uid, $password)) {
39        $c->delete_session('invalid user/pass');
40        $c->stash->{template} = 'ballot/login.tt';
41        return;
42    }
43    $c->session->{uid} = $uid;
44    $c->session->{password} = $password;
45
46    my $vote = $c->model('Vote');
47    my %choices;
48    foreach ($vote->vote_choices($id)) {
49        $choices{$_->{key}} = $_->{label};
50    }
51    $c->stash->{choices} = { %choices };
52    $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') };
53
54    if ($c->req->param('confirm')) {
55        $vote->register_ballot(
56            $uid,
57            $id,
58            [ grep { $_ } (
59              map { $choices{$_} } $c->req->param('sbal'),
60              $c->req->param('fsbal'),
61            ) ],
62            $c->req->address,
63        ); # TODO trap error
64        $c->forward('done');
65    }
66}
67
68sub done : Private {
69    my ( $self, $c ) = @_;
70    $c->response->body('Vote réussi.');
71    $c->delete_session('Vote terminé');
72}
73
74=head1 AUTHOR
75
76Thauvin Olivier
77
78=head1 LICENSE
79
80This library is free software, you can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84
851;
Note: See TracBrowser for help on using the repository browser.