1 | package Epoll::Controller::Newpoll; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Epoll::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')->rollback; |
---|
27 | $c->model('Vote')->clean_old_poll_request and $c->model('Vote')->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 | my $reqid = $c->model('Vote')->create_poll_request( |
---|
36 | mail => $c->req->param('mail'), |
---|
37 | label => $c->req->param('label'), |
---|
38 | ); |
---|
39 | $c->forward( |
---|
40 | q'Epoll::View::Mail', 'render', |
---|
41 | [ 'poll_request.tt', { |
---|
42 | To => $c->req->param('mail'), |
---|
43 | Subject => "New poll request", |
---|
44 | mail => { |
---|
45 | label => $c->req->param('label'), |
---|
46 | reqid => $reqid, |
---|
47 | } |
---|
48 | } ] |
---|
49 | ); |
---|
50 | |
---|
51 | $c->stash->{template} = 'newpoll/request.tt'; |
---|
52 | } |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | sub default : LocalPath { |
---|
57 | my ( $self, $c, undef, $id ) = @_; |
---|
58 | |
---|
59 | $id eq 'confirm' and $id = $c->req->param('id') || ''; |
---|
60 | $c->stash->{reqid} = $id; |
---|
61 | |
---|
62 | if (!$c->model('Vote')->poll_request_info($id)) { |
---|
63 | $c->stash->{page}{title} = "Aucune requête de création de vote"; |
---|
64 | $c->stash->{template} = 'newpoll/norequest.tt'; |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote'; |
---|
69 | if ($c->req->param('passwd')) { |
---|
70 | my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd')); |
---|
71 | my $uid = $c->model('Vote')->poll($pid)->uid; |
---|
72 | $c->session->{'vpass' . $uid} = $c->req->param('passwd'); # avoid auth on admin page |
---|
73 | $c->res->redirect($c->uri_for('/admin', $uid)); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | sub end : Private { |
---|
78 | my ($self, $c) = @_; |
---|
79 | if ($c->res->body) { return } |
---|
80 | else { $c->forward(qw/Epoll::View::TT/) } |
---|
81 | } |
---|
82 | |
---|
83 | =head1 AUTHOR |
---|
84 | |
---|
85 | Thauvin Olivier |
---|
86 | |
---|
87 | =head1 LICENSE |
---|
88 | |
---|
89 | This library is free software, you can redistribute it and/or modify |
---|
90 | it under the same terms as Perl itself or CeCILL. |
---|
91 | |
---|
92 | =cut |
---|
93 | |
---|
94 | 1; |
---|