package Vote::Controller::Ballot; use strict; use warnings; use base 'Catalyst::Controller'; =head1 NAME Vote::Controller::Ballot - Catalyst Controller =head1 DESCRIPTION Catalyst Controller. =head1 METHODS =cut =head2 index =cut sub index : Private { my ( $self, $c ) = @_; $c->response->body('Matched Vote::Controller::Ballot in Vote.'); } sub default : Private { my ( $self, $c, undef, $id ) = @_; $c->stash->{voteid} = $id; my $uid = $c->session->{uid} || $c->req->param('uid'); my $password = $c->session->{password} || $c->req->param('password'); if (!$c->model('Vote')->auth_voting($id, $uid, $password)) { $c->delete_session('invalid user/pass'); $c->stash->{template} = 'ballot/login.tt'; return; } $c->session->{uid} = $uid; $c->session->{password} = $password; my $vote = $c->model('Vote'); my %choices; foreach ($vote->vote_choices($id)) { $choices{$_->{key}} = $_->{label}; } $c->stash->{choices} = { %choices }; $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; if ($c->req->param('confirm')) { $vote->register_ballot( $uid, $id, [ grep { $_ } ( map { $choices{$_} } $c->req->param('sbal'), $c->req->param('fsbal'), ) ], $c->req->address, ); # TODO trap error $c->forward('done'); } } sub done : Private { my ( $self, $c ) = @_; $c->response->body('Vote réussi.'); $c->delete_session('Vote terminé'); } =head1 AUTHOR Thauvin Olivier =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;