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} = $c->localize('Create a new vote'); |
---|
34 | if ($c->req->param('mail')) { |
---|
35 | if ($c->config->{newpollpasswd}) { |
---|
36 | if (($c->req->param('passwd') || '') eq $c->config->{newpollpasswd}) |
---|
37 | { |
---|
38 | if (my $pid = $c->model('Vote')->create_poll( |
---|
39 | $c->req->param('mail'), |
---|
40 | $c->req->param('label'), |
---|
41 | $c->req->param('vpasswd'), |
---|
42 | ) |
---|
43 | ) { |
---|
44 | $c->session->{'vpass' . $pid} = $c->req->param('vpasswd'); # avoid auth on admin page |
---|
45 | $c->res->redirect($c->uri_for('/admin', |
---|
46 | $c->model('Vote')->poll_id_from_uid($pid)) |
---|
47 | ); |
---|
48 | } |
---|
49 | } else { |
---|
50 | $c->stash->{passwderror} = 1; |
---|
51 | } |
---|
52 | } else { |
---|
53 | my $reqid = $c->model('Vote')->create_poll_request( |
---|
54 | mail => $c->req->param('mail'), |
---|
55 | label => $c->req->param('label'), |
---|
56 | ); |
---|
57 | $c->forward( |
---|
58 | q'Epoll::View::Mail', 'render', |
---|
59 | [ 'poll_request.tt', { |
---|
60 | To => $c->req->param('mail'), |
---|
61 | Subject => $c->localize("New poll request"), |
---|
62 | mail => { |
---|
63 | label => $c->req->param('label'), |
---|
64 | reqid => $reqid, |
---|
65 | } |
---|
66 | } ] |
---|
67 | ); |
---|
68 | $c->stash->{template} = 'newpoll/request.tt'; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | sub default : LocalPath { |
---|
75 | my ( $self, $c, undef, $id ) = @_; |
---|
76 | |
---|
77 | $id eq 'confirm' and $id = $c->req->param('id') || ''; |
---|
78 | $c->stash->{reqid} = $id; |
---|
79 | |
---|
80 | if (!$c->model('Vote')->poll_request_info($id)) { |
---|
81 | $c->stash->{page}{title} = $c->localize("No vote creation request"); |
---|
82 | $c->stash->{template} = 'newpoll/norequest.tt'; |
---|
83 | return; |
---|
84 | } |
---|
85 | |
---|
86 | $c->stash->{page}{title} = $c->localize('Confirm new vote creation'); |
---|
87 | if ($c->req->param('passwd')) { |
---|
88 | my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd')); |
---|
89 | my $uid = $c->model('Vote')->poll($pid)->uid; |
---|
90 | $c->session->{'vpass' . $uid} = $c->req->param('passwd'); # avoid auth on admin page |
---|
91 | $c->res->redirect($c->uri_for('/admin', $uid)); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | sub end : Private { |
---|
96 | my ($self, $c) = @_; |
---|
97 | if ($c->res->body) { return } |
---|
98 | else { $c->forward(qw/Epoll::View::TT/) } |
---|
99 | } |
---|
100 | |
---|
101 | =head1 AUTHOR |
---|
102 | |
---|
103 | Thauvin Olivier |
---|
104 | |
---|
105 | =head1 LICENSE |
---|
106 | |
---|
107 | This library is free software, you can redistribute it and/or modify |
---|
108 | it under the same terms as Perl itself or CeCILL. |
---|
109 | |
---|
110 | =cut |
---|
111 | |
---|
112 | 1; |
---|