1 # Selectricity: Voting Machinery for the Masses
2 # Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
3 # Copyright (C) 2007 Massachusetts Institute of Technology
5 # This program is free software. Please see the COPYING file for
8 class VoterController < ApplicationController
11 require_dependency "voter"
12 require_dependency "vote"
13 require_dependency "election"
16 if params[:election_id]
17 @election = Election.find(params[:election_id])
18 unless @election.authenticated?
19 @voter = OpenVoter.find(:all,
20 :conditions => ["session_id = ? and election_id = ?",
21 session.session_id, @election.id])[0]
23 unless @voter and not @voter.election.kiosk
24 @voter = OpenVoter.new
27 @voter.election = @election
28 @voter.session_id = session.session_id
29 @password = "open." + @election.id.to_s
31 elsif params[:urlpassword]
32 password = params[:urlpassword]
34 if @voter = FullVoter.find(:all,
35 :conditions => [ "password = ?", password ] )[0]
36 @election = @voter.election
37 @password = @voter.password
41 if @voter and @election
42 # initialize things if the vote is blank
44 @voter.vote = Vote.new
48 @voter.vote.set_defaults! if @voter.vote.rankings.empty?
50 # if the election is now finished
51 if @election.enddate < Time.now
52 redirect_to :action => :results, :id => @password
54 @sidebar_content = render_to_string(:partial => 'vote_sidebar')
55 if @election.embeddable? and params[:embed] == "true"
56 #look for custom theme, and assign to instance variabels for widget use
57 if @election.embed_custom_string
58 @top_bar = SkinPicture.find(:first,
59 :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
60 @default_image = SkinPicture.find(:first,
61 :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
62 @bg1 = SkinPicture.find(:first,
63 :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
64 @bg2 = SkinPicture.find(:first,
65 :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
66 @bottom_bar = SkinPicture.find(:first,
67 :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
69 render :template => 'embed/full_vote', :layout => 'embed'
71 render :action => 'full_vote'
78 if params[:vote] and params[:vote][:password]
79 redirect_to votepassword_url( :action => 'index', :urlpassword => params[:vote][:password])
81 redirect_to :action => 'index'
87 @election = @voter.election
88 @results = @election.results
90 @election.candidates.each {|c| @candidates[c.id] = c}
91 @names = @election.names_by_id
92 render :template => 'common/pref_tables', :layout => 'basic'
94 redirect_to :action => 'index'
100 @election = @voter.election
101 @votes = @election.votes.select {|v| v.confirmed? }.shuffle
102 @voters = @votes.collect {|v| v.voter}.shuffle
103 render :action => 'details'
105 redirect_to :action => 'index'
111 @voter.vote.time = Time.now
115 redirect_to :action => 'index'
123 if @voter.election.embeddable? and params[:embed] == "true" \
124 and @voter.election.early_results?
125 redirect_to :action => :results, :id => @password, :embed => 'true'
126 elsif @voter.election.kiosk and params[:kiosk] = "true"
127 redirect_to :action => "kiosk_ready", :id => @password, :kiosk => true
129 render :action => 'thanks'
132 redirect_to :action => 'index'
138 voter_array= FullVoter.find(:all, :conditions => ["email = ?", params[:email]])
139 voter_array.delete_if {|voter| voter.election.active == 0}
140 unless voter_array.empty?
141 VoterNotify.deliver_reminder(voter_array)
143 render :action => 'reminder_sent'
149 (@voter.election.early_results? \
150 or @voter.election.enddate < Time.now)
152 @election = @voter.election
153 # compute and display results
155 @results = @election.results
157 @election.candidates.each {|c| @candidates[c.id] = c}
158 @names = @election.names_by_id
160 @sidebar_content = render_to_string(:partial => 'results_sidebar')
161 #look for custom theme, and assign to instance variabels for widget use
162 if @election.embed_custom_string
163 @top_bar = SkinPicture.find(:first,
164 :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
165 @default_image = SkinPicture.find(:first,
166 :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
167 @bg1 = SkinPicture.find(:first,
168 :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
169 @bg2 = SkinPicture.find(:first,
170 :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
171 @bottom_bar = SkinPicture.find(:first,
172 :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
174 if @election.embeddable? and params[:embed] == "true"
175 render :template => 'embed/results', :layout => 'embed'
177 render :action => 'results'
180 redirect_to :action => 'index'
186 redirect_to :action => 'index', :kiosk => true
192 password = params[:id]
193 if password == "open"
194 election = Election.find(params[:format])
195 unless election.authenticated?
196 @voter = OpenVoter.find(:all,
197 :conditions => ["session_id = ? and election_id = ?",
198 session.session_id, election.id])[0]
199 @password = "open." + election.id.to_s
202 @voter = FullVoter.find(:all,
203 :conditions => [ "password = ?", password ] )[0]
204 @password = @voter.password