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: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with this program. If not, see
17 # <http://www.gnu.org/licenses/>.
19 class VoterController < ApplicationController
21 require_dependency "voter"
22 require_dependency "vote"
23 require_dependency "election"
26 if params[:urlpassword]
27 password = params[:urlpassword]
29 if @voter = FullVoter.find(:all,
30 :conditions => [ "password = ?", password ] )[0]
32 @voter.vote = Vote.new if @voter.vote.nil?
33 @voter.vote.set_defaults! if @voter.vote.rankings.empty?
35 @election = @voter.election
37 # if the election is now finished
38 if @election.enddate < Time.now
39 # compute and display results
41 @results = @election.results
43 @election.candidates.each {|c| @candidates[c.id] = c}
44 @names = @election.names_by_id
46 @sidebar_content = render_to_string(:partial => 'results_sidebar')
47 render :action => 'results'
49 @sidebar_content = render_to_string(:partial => 'vote_sidebar')
50 render :action => 'full_vote'
52 elsif params[:urlpassword]
53 redirect_to :action => 'index'
59 if params[:vote] and params[:vote][:password]
60 redirect_to votepassword_url( :action => 'index', :urlpassword => params[:vote][:password])
62 redirect_to :action => 'index'
68 @election = @voter.election
69 @results = @election.results
71 @election.candidates.each {|c| @candidates[c.id] = c}
72 @names = @election.names_by_id
73 render :template => 'common/pref_tables', :layout => 'basic'
75 redirect_to :action => 'index'
81 @election = @voter.election
82 @votes = @election.votes.select {|v| v.confirmed? }.randomize
83 @voters = @votes.collect {|v| v.voter}.randomize
84 render :action => 'details'
86 redirect_to :action => 'index'
92 @voter.vote.time = Time.now
96 redirect_to :action => 'index'
103 render :action => 'thanks'
105 redirect_to :action => 'index'
111 voter_array= FullVoter.find(:all, :conditions => ["email = ?", params[:email]])
112 voter_array.delete_if {|voter| voter.election.active == 0}
113 unless voter_array.empty?
114 VoterNotify.deliver_reminder(voter_array)
116 render :action => 'reminder_sent'
123 password = params[:id]
124 @voter = FullVoter.find(:all, :conditions => [ "password = ?", password ] )[0]