source: trunk/lib/Vote/Controller/Newpoll.pm @ 198

Last change on this file since 198 was 198, checked in by nanardon, 15 years ago
  • use new commit() and rollback()
  • add add standalone create_poll function
File size: 2.0 KB
Line 
1package Vote::Controller::Newpoll;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7=head1 NAME
8
9Vote::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'Vote::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    $c->stash->{reqid} = $id;
60
61    if (!$c->model('Vote')->poll_request_info($id)) {
62        $c->stash->{page}{title} = "Aucune requête de création de vote";
63        $c->stash->{template} = 'newpoll/norequest.tt';
64        return;
65    }
66
67    $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote';
68    if ($c->req->param('passwd')) {
69        my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd'));
70        $c->session->{'vpass' . $pid} = $c->req->param('passwd'); # avoid auth on admin page
71        $c->res->redirect($c->uri_for('/admin', $pid));
72    }
73}
74
75sub end : Private {
76    my ($self, $c) = @_;
77    if ($c->res->body) { return }
78    else { $c->forward(qw/Vote::View::TT/) }
79}
80
81=head1 AUTHOR
82
83Thauvin Olivier
84
85=head1 LICENSE
86
87This library is free software, you can redistribute it and/or modify
88it under the same terms as Perl itself or CeCILL.
89
90=cut
91
921;
Note: See TracBrowser for help on using the repository browser.