[242] | 1 | package Epoll::Controller::Newpoll; |
---|
[30] | 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use base 'Catalyst::Controller'; |
---|
| 6 | |
---|
| 7 | =head1 NAME |
---|
| 8 | |
---|
[242] | 9 | Epoll::Controller::Newpoll - Catalyst Controller |
---|
[30] | 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 ) = @_; |
---|
[198] | 26 | $c->model('Vote')->rollback; |
---|
| 27 | $c->model('Vote')->clean_old_poll_request and $c->model('Vote')->commit; |
---|
[53] | 28 | } |
---|
| 29 | |
---|
[30] | 30 | sub index : Private { |
---|
| 31 | my ( $self, $c ) = @_; |
---|
| 32 | |
---|
[366] | 33 | $c->stash->{page}{title} = $c->localize('Create a new vote'); |
---|
[30] | 34 | if ($c->req->param('mail')) { |
---|
[307] | 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( |
---|
[308] | 39 | $c->req->param('mail'), |
---|
[307] | 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; |
---|
[180] | 51 | } |
---|
[307] | 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'), |
---|
[366] | 61 | Subject => $c->localize("New poll request"), |
---|
[307] | 62 | mail => { |
---|
| 63 | label => $c->req->param('label'), |
---|
| 64 | reqid => $reqid, |
---|
| 65 | } |
---|
| 66 | } ] |
---|
| 67 | ); |
---|
| 68 | $c->stash->{template} = 'newpoll/request.tt'; |
---|
| 69 | } |
---|
[30] | 70 | } |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | sub default : LocalPath { |
---|
| 75 | my ( $self, $c, undef, $id ) = @_; |
---|
| 76 | |
---|
[257] | 77 | $id eq 'confirm' and $id = $c->req->param('id') || ''; |
---|
[30] | 78 | $c->stash->{reqid} = $id; |
---|
| 79 | |
---|
[116] | 80 | if (!$c->model('Vote')->poll_request_info($id)) { |
---|
[366] | 81 | $c->stash->{page}{title} = $c->localize("No vote creation request"); |
---|
[116] | 82 | $c->stash->{template} = 'newpoll/norequest.tt'; |
---|
[117] | 83 | return; |
---|
[116] | 84 | } |
---|
| 85 | |
---|
[366] | 86 | $c->stash->{page}{title} = $c->localize('Confirm new vote creation'); |
---|
[30] | 87 | if ($c->req->param('passwd')) { |
---|
| 88 | my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd')); |
---|
[257] | 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)); |
---|
[30] | 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
[180] | 95 | sub end : Private { |
---|
| 96 | my ($self, $c) = @_; |
---|
| 97 | if ($c->res->body) { return } |
---|
[242] | 98 | else { $c->forward(qw/Epoll::View::TT/) } |
---|
[180] | 99 | } |
---|
| 100 | |
---|
[30] | 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 |
---|
[128] | 108 | it under the same terms as Perl itself or CeCILL. |
---|
[30] | 109 | |
---|
| 110 | =cut |
---|
| 111 | |
---|
| 112 | 1; |
---|