1 class VoterController < ApplicationController
3 require_dependency "voter"
4 require_dependency "vote"
5 require_dependency "election"
8 if params[:urlpassword]
9 password = params[:urlpassword]
11 if @voter = FullVoter.find(:all,
12 :conditions => [ "password = ?", password ] )[0]
14 @voter.vote = Vote.new if @voter.vote.nil?
15 @voter.vote.set_defaults! if @voter.vote.rankings.empty?
17 @election = @voter.election
19 # if the election is now finished
20 if @election.enddate < Time.now
21 # compute and display results
23 @results = @election.results
25 @election.candidates.each {|c| @candidates[c.id] = c}
26 @names = @election.names_by_id
28 @sidebar_content = render_to_string(:partial => 'results_sidebar')
29 render :action => 'results'
31 @sidebar_content = render_to_string(:partial => 'vote_sidebar')
32 render :action => 'full_vote'
34 elsif params[:urlpassword]
35 redirect_to :action => 'index'
41 if params[:vote] and params[:vote][:password]
42 redirect_to votepassword_url( :action => 'index', :urlpassword => params[:vote][:password])
44 redirect_to :action => 'index'
50 @election = @voter.election
51 @results = @election.results
53 @election.candidates.each {|c| @candidates[c.id] = c}
54 @names = @election.names_by_id
55 render :template => 'common/pref_tables', :layout => 'basic'
57 redirect_to :action => 'index'
63 @election = @voter.election
64 @votes = @election.votes.select {|v| v.confirmed? }.randomize
65 @voters = @votes.collect {|v| v.voter}.randomize
66 render :action => 'details'
68 redirect_to :action => 'index'
74 @voter.vote.time = Time.now
78 redirect_to :action => 'index'
85 render :action => 'thanks'
87 redirect_to :action => 'index'
93 voter_array= FullVoter.find(:all, :conditions => ["email = ?", params[:email]])
94 voter_array.delete_if {|voter| voter.election.active == 0}
95 unless voter_array.empty?
96 VoterNotify.deliver_reminder(voter_array)
98 render :action => 'reminder_sent'
105 password = params[:id]
106 @voter = FullVoter.find(:all, :conditions => [ "password = ?", password ] )[0]