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

Last change on this file since 257 was 257, checked in by nanardon, 14 years ago
  • after poll request, a form allow to enter the request id,
  • really remember password to avoid login just after poll password setup
File size: 2.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} = '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
56sub 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
77sub 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
85Thauvin Olivier
86
87=head1 LICENSE
88
89This library is free software, you can redistribute it and/or modify
90it under the same terms as Perl itself or CeCILL.
91
92=cut
93
941;
Note: See TracBrowser for help on using the repository browser.