[30] | 1 | package Vote::Controller::Newpoll; |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use base 'Catalyst::Controller'; |
---|
| 6 | |
---|
| 7 | =head1 NAME |
---|
| 8 | |
---|
| 9 | Vote::Controller::Newpoll - Catalyst Controller |
---|
| 10 | |
---|
| 11 | =head1 DESCRIPTION |
---|
| 12 | |
---|
| 13 | Catalyst Controller. |
---|
| 14 | |
---|
| 15 | =head1 METHODS |
---|
| 16 | |
---|
| 17 | =cut |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | =head2 index |
---|
| 21 | |
---|
| 22 | =cut |
---|
| 23 | |
---|
[53] | 24 | sub begin : Private { |
---|
| 25 | my ( $self, $c ) = @_; |
---|
| 26 | $c->model('Vote')->db->rollback; |
---|
| 27 | } |
---|
| 28 | |
---|
[30] | 29 | sub index : Private { |
---|
| 30 | my ( $self, $c ) = @_; |
---|
| 31 | |
---|
[49] | 32 | $c->stash->{page}{title} = 'Créer un nouveau vote'; |
---|
[30] | 33 | if ($c->req->param('mail')) { |
---|
[304] | 34 | if ($c->config->{newpollpasswd}) { |
---|
| 35 | if (($c->req->param('passwd') || '') eq $c->config->{newpollpasswd}) |
---|
| 36 | { |
---|
| 37 | if (my $pid = $c->model('Vote')->create_poll( |
---|
| 38 | $c->req->param('label'), |
---|
| 39 | $c->req->param('mail'), |
---|
| 40 | $c->req->param('vpasswd'), |
---|
| 41 | ) |
---|
| 42 | ) { |
---|
| 43 | $c->res->redirect($c->uri_for('/admin', $pid)); |
---|
| 44 | } |
---|
| 45 | } else { |
---|
| 46 | $c->stash->{passwderror} = 1; |
---|
| 47 | } |
---|
| 48 | } else { |
---|
| 49 | $c->model('Vote')->create_poll_request( |
---|
| 50 | mail => $c->req->param('mail'), |
---|
| 51 | url => $c->uri_for('/newpoll'), |
---|
| 52 | label => $c->req->param('label'), |
---|
| 53 | ); |
---|
| 54 | $c->stash->{template} = 'newpoll/request.tt'; |
---|
| 55 | } |
---|
[30] | 56 | } |
---|
| 57 | |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | sub default : LocalPath { |
---|
| 61 | my ( $self, $c, undef, $id ) = @_; |
---|
| 62 | |
---|
| 63 | $c->stash->{reqid} = $id; |
---|
| 64 | |
---|
[116] | 65 | if (!$c->model('Vote')->poll_request_info($id)) { |
---|
[117] | 66 | $c->stash->{page}{title} = "Aucune requête de création de vote"; |
---|
[116] | 67 | $c->stash->{template} = 'newpoll/norequest.tt'; |
---|
[117] | 68 | return; |
---|
[116] | 69 | } |
---|
| 70 | |
---|
[49] | 71 | $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote'; |
---|
[30] | 72 | if ($c->req->param('passwd')) { |
---|
| 73 | my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd')); |
---|
| 74 | $c->res->redirect($c->uri_for('/admin', $pid)); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | =head1 AUTHOR |
---|
| 79 | |
---|
| 80 | Thauvin Olivier |
---|
| 81 | |
---|
| 82 | =head1 LICENSE |
---|
| 83 | |
---|
| 84 | This library is free software, you can redistribute it and/or modify |
---|
[128] | 85 | it under the same terms as Perl itself or CeCILL. |
---|
[30] | 86 | |
---|
| 87 | =cut |
---|
| 88 | |
---|
| 89 | 1; |
---|