package Vote::Controller::Newpoll;

use strict;
use warnings;
use base 'Catalyst::Controller';

=head1 NAME

Vote::Controller::Newpoll - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index 

=cut

sub index : Private {
    my ( $self, $c ) = @_;

    if ($c->req->param('mail')) {
        $c->model('Vote')->create_poll_request(
            mail => $c->req->param('mail'),
            url => $c->uri_for('/newpoll'),
            label => $c->req->param('label'),
        );
    }

}

sub default : LocalPath {
    my ( $self, $c, undef, $id ) = @_;

    $c->stash->{reqid} = $id;

    if ($c->req->param('passwd')) {
        my $pid = $c->model('Vote')->poll_from_request($id, $c->req->param('passwd'));
        $c->res->redirect($c->uri_for('/admin', $pid));
    }
}

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
