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

Last change on this file since 172 was 172, checked in by nanardon, 15 years ago
  • add password to session after request confirm
File size: 1.6 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->session->{vpassword} = $c->req->param('passwd'); # avoid auth on admin page
60        $c->res->redirect($c->uri_for('/admin', $pid));
61    }
62}
63
64=head1 AUTHOR
65
66Thauvin Olivier
67
68=head1 LICENSE
69
70This library is free software, you can redistribute it and/or modify
71it under the same terms as Perl itself or CeCILL.
72
73=cut
74
751;
Note: See TracBrowser for help on using the repository browser.