Changeset 9 for trunk/lib


Ignore:
Timestamp:
03/06/09 05:09:15 (15 years ago)
Author:
nanardon
Message:
  • use session to store login/pass
Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote.pm

    r2 r9  
    1414#                 directory 
    1515 
    16 use Catalyst qw/-Debug ConfigLoader Static::Simple/; 
     16use Catalyst qw/ 
     17    -Debug 
     18    ConfigLoader 
     19    Static::Simple 
     20    Session 
     21    Session::Store::DBI 
     22    Session::State::Cookie 
     23    /; 
    1724 
    1825our $VERSION = '0.01'; 
     
    2936__PACKAGE__->config( name => 'Vote' ); 
    3037 
     38__PACKAGE__->config->{session} = { 
     39    expires   => 1800, 
     40    dbi_table => 'sessions', 
     41    dbi_dsn => 'noo', 
     42}; 
     43 
     44 
    3145# Start the application 
    3246__PACKAGE__->setup; 
     47 
     48# This is after because db config is in config file 
     49__PACKAGE__->config->{session}{dbi_dsn} = 'dbi:Pg:' . __PACKAGE__->config->{db}; 
    3350 
    3451 
  • trunk/lib/Vote/Controller/Ballot.pm

    r8 r9  
    3333    $c->stash->{voteid} = $id; 
    3434 
     35    my $uid = $c->session->{uid} || $c->req->param('uid'); 
     36    my $password = $c->session->{password} || $c->req->param('password'); 
     37 
     38    if (!($uid && $password)) { 
     39        $c->stash->{template} = 'ballot/login.tt'; 
     40        return; 
     41    } 
     42    $c->session->{uid} = $uid; 
     43    $c->session->{password} = $password; 
     44 
    3545    my $vote = $c->model('Vote'); 
    3646    my %choices; 
     
    3848        $choices{$_->{key}} = $_->{label}; 
    3949    } 
     50    $c->stash->{choices} = { %choices }; 
     51    $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; 
    4052 
    4153    my $uid = 'Olivier Thauvin'; # for test now 
    42     if ($c->req->param('ballot')) { 
     54    if ($c->req->param('confirm')) { 
    4355        $vote->register_ballot( 
    4456            $uid, 
     
    5062            $c->req->address, 
    5163        ); # TODO trap error 
     64        $c->forward('done'); 
    5265    } 
    5366} 
    5467 
     68sub done : Private { 
     69    my ( $self, $c ) = @_; 
     70    $c->response->body('Vote réussi.'); 
     71    $c->delete_session('Vote terminé'); 
     72} 
    5573 
    5674=head1 AUTHOR 
Note: See TracChangeset for help on using the changeset viewer.