Changeset 20


Ignore:
Timestamp:
03/08/09 15:36:06 (15 years ago)
Author:
nanardon
Message:
  • mark untrusted ballot
Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Controller/Ballot.pm

    r19 r20  
    6464    $c->stash->{choices} = { %choices }; 
    6565    $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; 
    66     $c->stash->{fsbal} = [ map { 
     66    $c->stash->{fsbal} = [ grep { $_ } map { 
    6767        s/^\s+//; 
    6868        s/\s+$//; 
     
    7171    } ($c->req->param('fsbal')) ]; 
    7272 
    73     my @torecord = grep { $_ } ( 
    74         (map { $choices{$_} } $c->req->param('sbal')), 
    75         @{ $c->stash->{fsbal} } 
    76     ); 
    77      
    78     if (scalar(@torecord) > $vote->vote_info($id)->{choice_count}) { 
     73    my @sbalval = grep { $_ } map { $choices{$_} } $c->req->param('sbal'); 
     74 
     75    if (scalar(@sbalval) + scalar(@{$c->stash->{fsbal} || []}) 
     76        > $vote->vote_info($id)->{choice_count}) { 
    7977        $c->req->param('ballot', ''); 
    8078        $c->stash->{vote_error} = 'Seulement ' . 
     
    8482    { 
    8583        my %uniq; 
    86         $uniq{lc($_)} foreach(@torecord); 
    87         if (scalar(keys %uniq) != scalar(@torecord)) { 
     84        $uniq{lc($_)} = 1 foreach(@sbalval, @{$c->stash->{fsbal} || []}); 
     85        if (scalar(keys %uniq) != scalar(@sbalval) + scalar(@{$c->stash->{fsbal} || []})) { 
    8886            $c->req->param('ballot', ''); 
    8987            $c->stash->{vote_error} = 'Une valeur est en double'; 
     
    9694            $uid, 
    9795            $id, 
    98             [ @torecord ], 
     96            [ @sbalval ], 
     97            [ @{ $c->stash->{fsbal} } ], 
    9998            $c->req->address, 
    10099        ); # TODO trap error 
  • trunk/lib/Vote/Model/Vote.pm

    r15 r20  
    221221 
    222222sub _register_ballot { 
    223     my ($self, $voteid, $choice) = @_; 
     223    my ($self, $voteid, $choice, $fchoice) = @_; 
    224224 
    225225    my $addb = $self->db->prepare_cached( 
    226226        q{ 
    227         insert into ballot (id, poll) values (?,?) 
     227        insert into ballot (id, poll, invalid) values (?,?,?) 
    228228        } 
    229229    ); 
    230230    my $uid = gen_uid; 
    231     $addb->execute($uid, $voteid) or do { 
     231    $addb->execute($uid, $voteid, scalar(@{$fchoice || []}) ? undef : 'f') or do { 
    232232        self->db->rollback; 
    233233        return; 
     
    236236    my $addbc = $self->db->prepare_cached( 
    237237        q{ 
    238         insert into ballot_item (id, value) values (?,?) 
     238        insert into ballot_item (id, value, fromlist) values (?,?,?) 
    239239        } 
    240240    ); 
    241241    foreach (@{ $choice || []}) { 
    242         $addbc->execute($uid, $_) or do { 
     242        $addbc->execute($uid, $_, 't') or do { 
    243243            $self->db->rollback; 
    244244            return; 
    245245        }; 
    246246    } 
     247    foreach (@{ $fchoice || []}) { 
     248        $addbc->execute($uid, $_, 'f') or do { 
     249            $self->db->rollback; 
     250            return; 
     251        }; 
     252    } 
    247253 
    248254    $uid; 
     
    250256 
    251257sub register_ballot { 
    252     my ($self, $vid, $voteid, $choice, $referal) = @_; 
     258    my ($self, $vid, $voteid, $choice, $fchoice, $referal) = @_; 
    253259 
    254260    # First we register voting has voted 
     
    256262 
    257263    # registring choices 
    258     my $uid = $self->_register_ballot($voteid, $choice) or return; 
     264    my $uid = $self->_register_ballot($voteid, $choice, $fchoice) or return; 
    259265 
    260266    # everything went fine, saving! 
Note: See TracChangeset for help on using the changeset viewer.