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

Last change on this file since 377 was 377, checked in by misc, 14 years ago
  • show a error message when the mail server is down
File size: 3.2 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} = $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            if ($c->stash->{mail_error}) { 
69                $c->stash->{template} = 'errors/mail.tt';
70            } else { 
71                $c->stash->{template} = 'newpoll/request.tt';
72            }
73        }
74    }
75
76}
77
78sub default : LocalPath {
79    my ( $self, $c, undef, $id ) = @_;
80
81    $id eq 'confirm' and $id = $c->req->param('id') || '';
82    $c->stash->{reqid} = $id;
83
84    if (!$c->model('Vote')->poll_request_info($id)) {
85        $c->stash->{page}{title} = $c->localize("No vote creation request");
86        $c->stash->{template} = 'newpoll/norequest.tt';
87        return;
88    }
89
90    $c->stash->{page}{title} = $c->localize('Confirm new vote creation');
91    if ($c->req->param('passwd')) {
92        my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd'));
93        my $uid = $c->model('Vote')->poll($pid)->uid;
94        $c->session->{'vpass' . $uid} = $c->req->param('passwd'); # avoid auth on admin page
95        $c->res->redirect($c->uri_for('/admin', $uid));
96    }
97}
98
99sub end : Private {
100    my ($self, $c) = @_;
101    if ($c->res->body) { return }
102    else { $c->forward(qw/Epoll::View::TT/) }
103}
104
105=head1 AUTHOR
106
107Thauvin Olivier
108
109=head1 LICENSE
110
111This library is free software, you can redistribute it and/or modify
112it under the same terms as Perl itself or CeCILL.
113
114=cut
115
1161;
Note: See TracBrowser for help on using the repository browser.