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 | |
---|
24 | sub begin : Private { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | $c->model('Vote')->db->rollback; |
---|
27 | $c->model('Vote')->clean_old_poll_request and $c->model('Vote')->db->commit; |
---|
28 | } |
---|
29 | |
---|
30 | sub index : Private { |
---|
31 | my ( $self, $c ) = @_; |
---|
32 | |
---|
33 | $c->stash->{page}{title} = 'Créer un nouveau vote'; |
---|
34 | if ($c->req->param('mail')) { |
---|
35 | $c->model('Vote')->create_poll_request( |
---|
36 | mail => $c->req->param('mail'), |
---|
37 | url => $c->uri_for('/newpoll'), |
---|
38 | label => $c->req->param('label'), |
---|
39 | ); |
---|
40 | $c->stash->{template} = 'newpoll/request.tt'; |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | sub default : LocalPath { |
---|
46 | my ( $self, $c, undef, $id ) = @_; |
---|
47 | |
---|
48 | $c->stash->{reqid} = $id; |
---|
49 | |
---|
50 | if (!$c->model('Vote')->poll_request_info($id)) { |
---|
51 | $c->stash->{page}{title} = "Aucune requête de création de vote"; |
---|
52 | $c->stash->{template} = 'newpoll/norequest.tt'; |
---|
53 | return; |
---|
54 | } |
---|
55 | |
---|
56 | $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote'; |
---|
57 | if ($c->req->param('passwd')) { |
---|
58 | my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd')); |
---|
59 | $c->session->{vpassword} = $c->req->param('passwd'); # avoid auth on admin page |
---|
60 | $c->res->redirect($c->uri_for('/admin', $pid)); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | =head1 AUTHOR |
---|
65 | |
---|
66 | Thauvin Olivier |
---|
67 | |
---|
68 | =head1 LICENSE |
---|
69 | |
---|
70 | This library is free software, you can redistribute it and/or modify |
---|
71 | it under the same terms as Perl itself or CeCILL. |
---|
72 | |
---|
73 | =cut |
---|
74 | |
---|
75 | 1; |
---|