source: trunk/lib/Vote/Model/Vote.pm @ 139

Last change on this file since 139 was 139, checked in by nanardon, 15 years ago
  • fix mail sender (from Mail::Util man page)
File size: 21.0 KB
Line 
1package Vote::Model::Vote;
2
3use strict;
4use warnings;
5use base 'Catalyst::Model';
6use Vote;
7use DBI;
8use Mail::Mailer;
9
10=head1 NAME
11
12Vote::Model::Vote - Catalyst Model
13
14=head1 DESCRIPTION
15
16Catalyst Model.
17
18=cut
19
20sub new {
21    my ($class) = @_;
22   
23    bless {
24        db => _newdb(),
25    }, $class;
26}
27
28sub _newdb {
29    my $db = DBI->connect(
30        'dbi:Pg:' . Vote->config->{db},
31        undef, undef,
32        {
33            RaiseError => 0,
34            AutoCommit => 0,
35            PrintWarn => 0,
36            PrintError => 1,
37        }
38    ) or return;
39    $db->do(q{set DATESTYLE to 'DMY'});
40    return $db;
41}
42
43sub db {
44    return $_[0]->{db} && $_[0]->{db}->ping
45        ? $_[0]->{db}
46        : $_[0]->_newdb();
47}
48
49sub mail_header {
50    return(
51        'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
52        'Content-Transfer-Encoding' => '8bit',
53        'X-Epoll-version' => $Vote::VERSION,
54    );
55}
56
57sub random_string {
58    my $lenght = $_[-1] || 8;
59
60    return join('', map { ('a'..'z', 'A'..'Z', 0..9)[rand 62] } (1..$lenght));
61}
62
63sub gen_enc_passwd {
64    my ($self, $passwd) = @_;
65
66    $passwd ||= random_string(8);
67    return(crypt($passwd, '$1$' . random_string(8) . '$'));
68}
69
70sub dbtime {
71    my ($self) = @_;
72    my $sth = $self->db->prepare(
73        q{select to_char(now(), 'DD/MM/YYYY HH24:MI:SS') as d}
74    );
75
76    $sth->execute();
77    my $res = $sth->fetchrow_hashref;
78    $sth->finish;
79    $res->{d};
80}
81
82sub list_comming_vote {
83    my ($self) = @_;
84
85    my $sth = $self->db->prepare_cached(
86        q{
87        select id from poll where
88        (start > now() and "end" > now()) or
89        "end" is null or start is null
90        }
91    );
92
93    $sth->execute;
94    my @id;
95    while(my $res = $sth->fetchrow_hashref) {
96        push(@id, $res->{id});
97    }
98
99    @id
100}
101
102
103sub list_running_vote {
104    my ($self) = @_;
105
106    my $sth = $self->db->prepare_cached(
107        q{
108        select id from poll where start < now() and "end" > now()
109        }
110    );
111
112    $sth->execute;
113    my @id;
114    while(my $res = $sth->fetchrow_hashref) {
115        push(@id, $res->{id});
116    }
117
118    @id
119}
120
121sub list_closed_vote {
122    my ($self) = @_;
123
124    my $sth = $self->db->prepare_cached(
125        q{
126        select id from poll where
127        start < now() and "end" < now()
128        }
129    );
130
131    $sth->execute;
132    my @id;
133    while(my $res = $sth->fetchrow_hashref) {
134        push(@id, $res->{id});
135    }
136
137    @id
138}
139
140sub vote_param {
141    my ($self, $voteid, %attr) = @_;
142
143    keys %attr or return;
144    my @online_f = qw(label start end owner password);
145
146    if (grep { exists($attr{$_}) } @online_f) {
147        my $sth = $self->db->prepare_cached(
148            q{update poll set } .
149            join(',', map { qq("$_" = ?) } grep { exists $attr{$_} } @online_f) .
150            q{ where id = ?}
151        );
152        $sth->execute((map { $attr{$_} } grep { exists $attr{$_} } @online_f), $voteid)
153            or do {
154            $self->db->rollback;
155            return;
156        };
157    }
158
159    # vote settings in settings table
160    foreach my $var (keys %attr) {
161        grep { $var eq $_ } @online_f and next;
162        $self->vote_set_settings($voteid, $var, $attr{$var});
163    }
164    1
165}
166
167sub vote_status {
168    my ($self, $id) = @_;
169   
170    my $sth = $self->db->prepare_cached(
171        q{
172        select (start > now() or start is null) as before,
173               "end" < now() as after
174        from poll
175        where id = ?
176        }
177    );
178    $sth->execute($id);
179    my $res = $sth->fetchrow_hashref;
180    $sth->finish;
181    $res or return;
182    if ($res->{before}) {
183        return 'BEFORE';
184    } elsif ($res->{after}) {
185        return 'AFTER';
186    } else {
187        return 'RUNNING';
188    }
189}
190
191sub vote_info {
192    my ($self, $id) = @_;
193
194    my $sth = $self->db->prepare_cached(
195        q{
196        select *,
197        to_char("start", 'DD/MM/YYYY') as dstart,
198        to_char("start", 'HH24:MI:SS') as hstart,
199        to_char("end", 'DD/MM/YYYY') as dend,
200        to_char("end", 'HH24:MI:SS') as hend
201        from poll where id = ?
202        }
203    );
204
205    $sth->execute($id);
206    my $res = $sth->fetchrow_hashref;
207    $sth->finish;
208    if ($res) {
209        my $get = $self->db->prepare_cached(
210            q{select var, val from settings where poll = ?}
211        );
212        $get->execute($id);
213        while (my $set = $get->fetchrow_hashref) {
214            $res->{$set->{var}} = $set->{val};
215        }
216    }
217    $res->{free_choice} ||= 0; # avoiding undef
218    $res
219}
220
221sub vote_set_settings {
222    my ($self, $poll, $var, $val) = @_;
223
224    my $upd = $self->db->prepare_cached(
225        q{update settings set val = ? where poll = ? and var = ?}
226    );
227
228    if ($upd->execute($val, $poll, $var) == 0) {
229        my $add = $self->db->prepare_cached(
230            q{insert into settings (poll, var, val) values (?,?,?)}
231        );
232
233        $add->execute($poll, $var, $val);
234    }
235}
236
237sub vote_signing {
238    my ($self, $id) = @_;
239
240    my $sth = $self->db->prepare_cached(
241        q{
242        select *, voting.key as vkey from voting left join signing
243        on signing.key = voting.key
244        where poll = ? order by voting.mail
245        }
246    );
247    $sth->execute($id);
248    my @people;
249    while (my $res = $sth->fetchrow_hashref) {
250        push(@people, $res);
251    }
252    @people
253}
254
255sub vote_voting {
256    my ($self, $voteid) = @_;
257
258    my $sth = $self->db->prepare_cached(
259        q{
260        select key from voting
261        where poll = ? order by voting.mail
262        }
263    );
264    $sth->execute($voteid);
265    my @people;
266    while (my $res = $sth->fetchrow_hashref) {
267        push(@people, $res->{key});
268    }
269    @people
270}
271
272sub voting_info {
273    my ($self, $id) = @_;
274
275    my $sth = $self->db->prepare_cached(
276        q{
277        select *, voting.key as vkey from voting left join signing
278        on signing.key = voting.key
279        where voting.key = ?
280        }
281    );
282    $sth->execute($id);
283
284    my $res = $sth->fetchrow_hashref;
285    $sth->finish;
286    $res
287}
288
289sub vote_choices {
290    my ($self, $id) = @_;
291
292    my $sth = $self->db->prepare_cached(
293        q{
294        select key from choice where poll = ?
295        order by label
296        }
297    );
298    $sth->execute($id);
299    my @ch;
300    while (my $res = $sth->fetchrow_hashref) {
301        push(@ch, $res->{key});
302    }
303    @ch
304}
305
306sub choice_info {
307    my ($self, $chid) = @_;
308    my $sth = $self->db->prepare_cached(
309        q{select * from choice where key = ?}
310    );
311    $sth->execute($chid);
312    my $res = $sth->fetchrow_hashref;
313    $sth->finish;
314    $res
315}
316
317sub vote_add_choice {
318    my ($self, $voteid, $label) = @_;
319
320    my $sth = $self->db->prepare_cached(
321        q{insert into choice (poll, label) values (?,?)}
322    );
323
324    $sth->execute($voteid, $label) or do {
325        $self->db->rollback;
326        return;
327    };
328
329    1
330}
331
332sub modify_choice {
333    my ($self, $chid, $label) = @_;
334
335    my $sth = $self->db->prepare_cached(
336        q{update choice set label = ? where key = ?}
337    );
338    $sth->execute($label, $chid);
339}
340
341sub delete_choice {
342    my ($self, $chid) = @_;
343
344    my $sth = $self->db->prepare_cached(
345        q{delete from choice where key = ?}
346    );
347
348    $sth->execute($chid);
349}
350
351sub voting_info_id {
352    my ($self, $mail, $voteid) = @_;
353
354    my $sth = $self->db->prepare_cached(
355        q{
356        select * from voting where mail = ? and poll = ?
357        }
358    );
359    $sth->execute($mail, $voteid);
360    my $res = $sth->fetchrow_hashref();
361    $sth->finish;
362    $res
363}
364
365sub _register_signing {
366    my ($self, $mail, $voteid, $referal) = @_;
367
368    my $vinfo = $self->voting_info_id($mail, $voteid) or return;
369
370    my $sth = $self->db->prepare_cached(
371        q{
372        insert into signing (key, referal) values (?,?)
373        }
374    );
375    $sth->execute($vinfo->{key}, $referal) or do {
376        $self->db->rollback;
377        return;
378    };
379
380    1;
381}
382
383sub gen_uid {
384    unpack("H*", join("", map { chr(rand(256)) } (0..15)))
385}
386
387sub _register_ballot {
388    my ($self, $voteid, $choice, $fchoice) = @_;
389
390    my $addb = $self->db->prepare_cached(
391        q{
392        insert into ballot (id, poll, invalid) values (?,?,?)
393        }
394    );
395    my $uid = gen_uid;
396    $addb->execute($uid, $voteid, scalar(@{$fchoice || []}) ? undef : 'f') or do {
397        self->db->rollback;
398        return;
399    };
400
401    my $addbc = $self->db->prepare_cached(
402        q{
403        insert into ballot_item (id, value, fromlist) values (?,?,?)
404        }
405    );
406    foreach (@{ $choice || []}) {
407        $addbc->execute($uid, $_, 't') or do {
408            $self->db->rollback;
409            return;
410        };
411    }
412    foreach (@{ $fchoice || []}) {
413        $_ or next;
414        $addbc->execute($uid, $_, 'f') or do {
415            $self->db->rollback;
416            return;
417        };
418    }
419
420    $uid;
421}
422
423sub register_ballot {
424    my ($self, $vid, $voteid, $choice, $fchoice, $referal) = @_;
425
426    my $uid;
427    for (0..2) { # 3 try
428    # First we register voting has voted
429    $self->_register_signing($vid, $voteid, $referal) or return; # TODO error ?
430
431    # registring choices
432    $uid = $self->_register_ballot($voteid, $choice, $fchoice);
433    defined($uid) and last;
434
435    }
436    # everything went fine, saving!
437    $self->db->commit;
438
439   
440    $uid
441}
442
443sub mail_ballot_confirm {
444    my ($self, $vid, $voteid, $info) = @_;
445    my $voteinfo = $self->vote_info($voteid) or return;
446    $info->{ballotid} or return;
447    my $mailer = new Mail::Mailer 'smtp', Server => (Vote->config->{smtp} || 'localhost');
448    $ENV{MAILADDRESS} = $vid;
449    $mailer->open({
450        From => $vid, # TODO allow to configure this
451        To => $vid,
452        Subject => 'Confirmation de vote: ' . $voteinfo->{label},
453        mail_header(),
454    });
455    print $mailer <<EOF;
456
457Vous venez de participer au vote:
458
459--------
460$voteinfo->{label}
461--------
462
463Votre bulletin est idéntifié sous le numéro:
464$info->{ballotid}
465
466Les résultats seront disponibles à cet url:
467$info->{url}
468
469Cordialement.
470EOF
471    $mailer->close
472        or warn "couldn't send whole message: $!\n";
473
474}
475
476sub vote_voting_count {
477    my ($self, $id) = @_;
478
479    my $sth = $self->db->prepare_cached(
480        q{
481        select count(*) from voting
482        where poll = ?
483        }
484    );
485    $sth->execute($id);
486    my $res = $sth->fetchrow_hashref;
487    $sth->finish;
488    $res->{count}
489}
490
491sub signing_count { vote_signing_count(@_) }
492
493sub vote_signing_count {
494    my ($self, $voteid) = @_;
495
496    my $sth = $self->db->prepare_cached(
497        q{
498        select count(*) from signing join voting
499        on voting.key = signing.key where poll = ?
500        }
501    );
502
503    $sth->execute($voteid);
504    my $res = $sth->fetchrow_hashref;
505    $sth->finish;
506    $res->{count}
507}
508
509sub ballot_count { vote_ballot_count(@_) }
510
511sub vote_ballot_count {
512    my ($self, $voteid) = @_;
513
514    my $sth = $self->db->prepare_cached(
515        q{
516        select count(*) from ballot where poll = ?
517        }
518    );
519
520    $sth->execute($voteid);
521    my $res = $sth->fetchrow_hashref;
522    $sth->finish;
523    $res->{count}
524}
525
526sub ballot_count_nonull { vote_ballot_count_nonull(@_) }
527
528sub vote_ballot_count_nonull {
529    my ($self, $voteid) = @_;
530
531    my $sth = $self->db->prepare_cached(
532        q{
533        select count(*) from ballot where poll = ?
534        and id in (select id from ballot_item) and
535        (invalid = 'false' or invalid is null)
536        }
537    );
538
539    $sth->execute($voteid);
540    my $res = $sth->fetchrow_hashref;
541    $sth->finish;
542    $res->{count}
543}
544
545sub auth_voting {
546    my ($self, $poll, $mail, $password) = @_;
547    my $userinfo = $self->voting_info_id($mail, $poll) or return;
548
549    $userinfo->{passwd} or return;
550    if (crypt($password, $userinfo->{passwd} || '') eq $userinfo->{passwd}) {
551        return 1;
552    } else {
553        return 0;
554    }
555}
556
557sub auth_poll {
558    my ($self, $voteid, $passwd) = @_;
559
560    my $vinfo = $self->vote_info($voteid) or return;
561
562    $vinfo->{password} or return;
563    $passwd or return;
564    if (crypt($passwd, $vinfo->{password} || '') eq $vinfo->{password}) {
565        return 1;
566    } else {
567        return 0;
568    }
569}
570
571sub voting_has_sign {
572    my ($self, $poll, $user) = @_;
573
574    my $sth = $self->db->prepare_cached(
575        q{
576        select date from signing join voting
577        on voting.key = signing.key
578        where poll = ? and mail = ?
579        }
580    );
581
582    $sth->execute($poll, $user);
583    my $res = $sth->fetchrow_hashref;
584    $sth->finish;
585    return $res->{date}
586}
587
588# Requete de decompte des voix:
589
590sub vote_results_count {
591    my ($self, $voteid) = @_;
592
593    my $sth = $self->db->prepare(
594        q{
595        select count(ballot.id), value from ballot left join ballot_item
596        on ballot.id = ballot_item.id where ballot.poll = ? and invalid = 'false'
597        group by value
598        order by count
599        }
600    );
601    $sth->execute($voteid);
602    my @results;
603    while (my $res = $sth->fetchrow_hashref) {
604        push(@results, $res);
605    }
606    @results;
607}
608
609sub vote_results_nonull {
610    my ($self, $voteid) = @_;
611
612    my $sth = $self->db->prepare(
613        q{
614        select count(ballot.id), coalesce(corrected, value) as value
615        from ballot join ballot_item
616        on ballot.id = ballot_item.id where ballot.poll = ? and
617        (invalid = 'false' or invalid is null)
618        group by coalesce(corrected, value)
619        order by count desc
620        }
621    );
622    $sth->execute($voteid);
623    my @results;
624    while (my $res = $sth->fetchrow_hashref) {
625        push(@results, $res);
626    }
627    \@results;
628}
629
630sub list_vote_ballot {
631    my ($self, $voteid) = @_;
632
633    my $sth = $self->db->prepare_cached(
634        q{
635        select id from ballot where poll = ?
636        order by id
637        }
638    );
639    $sth->execute($voteid);
640    my @ids;
641    while (my $res = $sth->fetchrow_hashref) {
642        push(@ids, $res->{id});
643    }
644    @ids
645}
646
647sub list_vote_ballot_needvalid {
648    my ($self, $voteid) = @_;
649
650    my $sth = $self->db->prepare_cached(
651        q{
652        select id from ballot where poll = ?
653        and invalid is null order by id
654        }
655    );
656    $sth->execute($voteid);
657    my @ids;
658    while (my $res = $sth->fetchrow_hashref) {
659        push(@ids, $res->{id});
660    }
661    @ids
662}
663
664sub ballot_info {
665    my ($self, $ballotid) = @_;
666
667    my $sth = $self->db->prepare_cached(
668        q{ select * from ballot where id = ? }
669    );
670
671    $sth->execute($ballotid);
672    my $res = $sth->fetchrow_hashref;
673    $sth->finish;
674    $res
675}
676
677sub mark_ballot_invalid {
678    my ($self, $ballotid, $invalid) = @_;
679
680    my $sth = $self->db->prepare_cached(
681        q{update ballot set invalid = ? where id = ?}
682    );
683
684    $sth->execute($invalid ? 't' : 'f', $ballotid);
685}
686
687sub ballot_items {
688    my ($self, $ballotid) = @_;
689
690    my $sth = $self->db->prepare_cached(
691        q{select *, value as v from ballot_item where id = ?}
692    );
693    $sth->execute($ballotid);
694    my @ids;
695    while (my $res = $sth->fetchrow_hashref) {
696        push(@ids, $res);
697    }
698    \@ids
699}
700
701sub vote_ballot_untrusted_values {
702    my ($self, $voteid) = @_;
703
704    my $getval = $self->db->prepare_cached(
705        q{
706        select value from ballot join ballot_item
707        on ballot.id = ballot_item.id
708        where poll = ? and fromlist = false and corrected is null
709        group by value order by value
710        }
711    );
712    $getval->execute($voteid);
713    my @vals;
714    while (my $res = $getval->fetchrow_hashref) {
715        push(@vals, $res->{value});
716    }
717    @vals
718}
719
720sub vote_ballot_values {
721    my ($self, $voteid) = @_;
722
723    my $getval = $self->db->prepare_cached(
724        q{
725        select coalesce(corrected, value) as value from ballot join ballot_item
726        on ballot.id = ballot_item.id
727        where poll = ?
728        group by coalesce(corrected, value) order by coalesce(corrected, value)
729        }
730    );
731    $getval->execute($voteid);
732    my @vals;
733    while (my $res = $getval->fetchrow_hashref) {
734        push(@vals, $res->{value});
735    }
736    @vals
737}
738
739sub vote_map_value {
740    my ($self, $voteid, $from, $to) = @_;
741
742    my $sth = $self->db->prepare_cached(
743        q{
744        update ballot_item set corrected = ? where
745        id in (select id from ballot where poll = ?)
746        and (value = ? or corrected = ?)
747        }
748    );
749
750    $sth->execute($to, $voteid, $from, $from) or $self->db->rollback;
751    $self->db->commit;
752}
753
754sub addupd_voting {
755    my ($self, $voteid, $mail, $id) = @_;
756
757    $mail =~ s/\s*$//;
758    $mail =~ s/^\s*//;
759    $id =~ s/\s*$//;
760    $id =~ s/^\s//;
761    my $upd = $self->db->prepare_cached(
762        q{
763        update voting set label = ? where mail = ? and poll = ?
764        }
765    );
766
767    if ($upd->execute($id || '', $mail, $voteid) == 0) {
768        my $add = $self->db->prepare_cached(q{
769            insert into voting (poll, label, mail) values (?,?,?)
770        });
771
772        $add->execute($voteid, $id || '', $mail);
773    }
774}
775
776sub delete_voting {
777    my ($self, $key) = @_;
778
779    $self->voting_has_sign($key) and return;
780    my $sth = $self->db->prepare_cached(
781        q{delete from voting where key = ?}
782    );
783
784    $sth->execute($key);
785}
786
787sub voting_from_file {
788    my ($self, $voteid, $fh, $delete) = @_;
789
790    if ($delete) {
791        my $sth = $self->db->prepare(q{delete from voting where poll = ?});
792        $sth->execute($voteid);
793    }
794
795    while (my $line = <$fh>) {
796        chomp($line);
797        my ($mail, $name) = split(';', $line);
798        $mail or do {
799            $self->db->rollback;
800            return;
801        };
802        $self->addupd_voting($voteid, $mail, $name || '');
803    }
804    1;
805}
806
807sub mail_passwd_ifnul {
808    my ($self, $voteid, $mailinfo) = @_;
809
810    my $list_voting = $self->db->prepare_cached(
811        q{select key from voting where poll = ? and passwd is null or passwd = ''}
812    );
813
814    $list_voting->execute($voteid);
815    while (my $res = $list_voting->fetchrow_hashref) {
816        $self->mail_voting_passwd($res->{key}, $mailinfo);
817    }
818}
819
820sub mail_voting_passwd {
821    my ($self, $id, $mailinfo) = @_;
822   
823    my $vinfo = $self->voting_info($id) or return;
824    my $voteinfo = $self->vote_info($vinfo->{poll});
825    $voteinfo->{description} ||= "";
826
827    my $passwd = random_string(8);
828    my $encpasswd = $self->gen_enc_passwd($passwd);
829
830    my $upd_voting = $self->db->prepare_cached(
831        q{update voting set passwd = ? where key = ?}
832    );
833
834    $upd_voting->execute($encpasswd, $id);
835
836    my $date = $voteinfo->{dstart} && $voteinfo->{dend}
837        ? sprintf("\n" . 'Vous pourrez voter entre le %s %s et le %s %s' . "\n",
838            $voteinfo->{dstart}, $voteinfo->{hstart}, $voteinfo->{dend}, $voteinfo->{hend})
839        : '';
840
841    # TODO complete this properly:
842    my $mailer = new Mail::Mailer 'smtp', Server => (Vote->config->{smtp} || 'localhost');
843    $ENV{MAILADDRESS} = $voteinfo->{owner};
844    $mailer->open({
845        From => $voteinfo->{owner},
846        To => $vinfo->{mail},
847        Subject => 'Invitation a voter: ' . $voteinfo->{label},
848        'X-Epoll-poll' => $id,
849        mail_header(),
850    });
851    print $mailer <<EOF;
852Vous êtes convié à participer a ce vote:
853
854--------
855$voteinfo->{label}
856--------
857$voteinfo->{description}
858--------
859
860à l'adresse:
861
862$mailinfo->{voteurl}
863$date
864Votre identifiant est: $vinfo->{mail}
865Votre mot de passe est: $passwd
866
867Conserver précieusement ces identifiants, il ne vous seront pas retransmit.
868
869Cordialement.
870EOF
871    $mailer->close or warn "couldn't send whole message: $!\n";
872
873    $self->db->commit;
874}
875
876sub poll_request_info {
877    my ($self, $rid) = @_;
878
879    my $sth = $self->db->prepare_cached(
880        q{select * from poll_request where id = ?}
881    );
882
883    $sth->execute($rid);
884    my $res = $sth->fetchrow_hashref;
885    $sth->finish;
886    $res
887}
888
889sub poll_from_request {
890    my ($self, $rid, $passwd) = @_;
891    my $rinfo = $self->poll_request_info($rid) or return;
892
893    my $encpasswd = $self->gen_enc_passwd($passwd);
894
895    my $getpollid = $self->db->prepare_cached(
896        q{select nextval('poll_id_seq')}
897    );
898    $getpollid->execute();
899    my $newpollid = $getpollid->fetchrow_hashref->{nextval};
900   
901    my $newpoll = $self->db->prepare_cached(
902        q{insert into poll (id, label, owner, password) values (?,?,?,?)}
903    );
904
905    $newpoll->execute($newpollid, $rinfo->{label}, $rinfo->{mail}, $encpasswd);
906    # set some default
907    $self->vote_param($newpollid,
908        free_choice => 0,
909        choice_count => 1,
910    );     
911
912    my $delreq = $self->db->prepare_cached(
913        q{delete from poll_request where id = ?}
914    );
915
916    $delreq->execute($rid);
917    $self->db->commit;
918
919    $newpollid
920}
921
922sub create_poll_request {
923    my ($self, %info) = @_;
924
925    $info{mail} or return;
926    my $addreq = $self->db->prepare_cached(
927        q{insert into poll_request (id, label, mail) values (?,?,?)}
928    );
929
930    my $reqid = gen_uid;
931
932    $addreq->execute($reqid, $info{label}, $info{mail});
933    my $mailer = new Mail::Mailer 'smtp', Server => (Vote->config->{smtp} || 'localhost');
934    $ENV{MAILADDRESS} = 'Voting system <nomail@nomail.com>';
935    $mailer->open({
936        From => 'Voting system <nomail@nomail.com>', # TODO allow to configure this
937        To => $info{mail},
938        Subject => 'Votre nouveau vote',
939        mail_header(),
940    });
941    print $mailer <<EOF;
942
943Vous avez demandez la création d'un nouveau vote:
944$info{label}
945
946Pour valider votre demande, veuiller allez visitez la page:
947$info{url}/$reqid
948
949A bientÃŽt
950EOF
951    $mailer->close
952        or warn "couldn't send whole message: $!\n";
953    $self->db->commit;
954    1;
955}
956
957=head1 AUTHOR
958
959Thauvin Olivier
960
961=head1 LICENSE
962
963This library is free software, you can redistribute it and/or modify
964it under the same terms as Perl itself or CeCILL.
965
966=cut
967
9681;
Note: See TracBrowser for help on using the repository browser.