source: branches/1/lib/Vote/Controller/Newpoll.pm @ 307

Last change on this file since 307 was 304, checked in by nanardon, 14 years ago
  • add a new config option making poll creation limit by admin password instead mail confirmation
File size: 2.1 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}
28
29sub index : Private {
30    my ( $self, $c ) = @_;
31
32    $c->stash->{page}{title} = 'Créer un nouveau vote';
33    if ($c->req->param('mail')) {
34        if ($c->config->{newpollpasswd}) {
35            if (($c->req->param('passwd') || '') eq $c->config->{newpollpasswd})
36                {
37                    if (my $pid = $c->model('Vote')->create_poll(
38                            $c->req->param('label'),
39                            $c->req->param('mail'),
40                            $c->req->param('vpasswd'),
41                        )
42                    ) {
43                        $c->res->redirect($c->uri_for('/admin', $pid));
44                    }
45                } else {
46                    $c->stash->{passwderror} = 1;
47                }
48        } else {
49            $c->model('Vote')->create_poll_request(
50                mail => $c->req->param('mail'),
51                url => $c->uri_for('/newpoll'),
52                label => $c->req->param('label'),
53            );
54            $c->stash->{template} = 'newpoll/request.tt';
55        }
56    }
57
58}
59
60sub default : LocalPath {
61    my ( $self, $c, undef, $id ) = @_;
62
63    $c->stash->{reqid} = $id;
64
65    if (!$c->model('Vote')->poll_request_info($id)) {
66        $c->stash->{page}{title} = "Aucune requête de création de vote";
67        $c->stash->{template} = 'newpoll/norequest.tt';
68        return;
69    }
70
71    $c->stash->{page}{title} = 'Confirmer la création d\'un nouveau vote';
72    if ($c->req->param('passwd')) {
73        my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd'));
74        $c->res->redirect($c->uri_for('/admin', $pid));
75    }
76}
77
78=head1 AUTHOR
79
80Thauvin Olivier
81
82=head1 LICENSE
83
84This library is free software, you can redistribute it and/or modify
85it under the same terms as Perl itself or CeCILL.
86
87=cut
88
891;
Note: See TracBrowser for help on using the repository browser.