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

Last change on this file since 170 was 170, checked in by nanardon, 15 years ago
  • delete old poll request creation (#6)
File size: 1.5 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')->db->rollback;
27    $c->model('Vote')->clean_old_poll_request and $c->model('Vote')->db->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        $c->model('Vote')->create_poll_request(
36            mail => $c->req->param('mail'),
37            url => $c->uri_for('/newpoll'),
38            label => $c->req->param('label'),
39        );
40        $c->stash->{template} = 'newpoll/request.tt';
41    }
42
43}
44
45sub default : LocalPath {
46    my ( $self, $c, undef, $id ) = @_;
47
48    $c->stash->{reqid} = $id;
49
50    if (!$c->model('Vote')->poll_request_info($id)) {
51        $c->stash->{page}{title} = "Aucune requête de création de vote";
52        $c->stash->{template} = 'newpoll/norequest.tt';
53        return;
54    }
55
56    $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote';
57    if ($c->req->param('passwd')) {
58        my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd'));
59        $c->res->redirect($c->uri_for('/admin', $pid));
60    }
61}
62
63=head1 AUTHOR
64
65Thauvin Olivier
66
67=head1 LICENSE
68
69This library is free software, you can redistribute it and/or modify
70it under the same terms as Perl itself or CeCILL.
71
72=cut
73
741;
Note: See TracBrowser for help on using the repository browser.