source: trunk/lib/Epoll/Controller/Newpoll.pm @ 307

Last change on this file since 307 was 307, checked in by nanardon, 14 years ago
  • add a new config option making poll creation limit by admin password instead mail confirmation (from branche/1)
File size: 3.0 KB
Line 
1package Epoll::Controller::Newpoll;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7=head1 NAME
8
9Epoll::Controller::Newpoll - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub 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
30sub index : Private {
31    my ( $self, $c ) = @_;
32
33    $c->stash->{page}{title} = 'Créer un nouveau 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('label'),
40                            $c->req->param('mail'),
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 => "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
74sub 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} = "Aucune requête de création de vote";
82        $c->stash->{template} = 'newpoll/norequest.tt';
83        return;
84    }
85
86    $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote';
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
95sub 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
103Thauvin Olivier
104
105=head1 LICENSE
106
107This library is free software, you can redistribute it and/or modify
108it under the same terms as Perl itself or CeCILL.
109
110=cut
111
1121;
Note: See TracBrowser for help on using the repository browser.