]> projects.mako.cc - selectricity-live/blob - app/controllers/voter_controller.rb
first (mostly) working version of full elections.
[selectricity-live] / app / controllers / voter_controller.rb
1 class VoterController < ApplicationController
2   layout 'main'
3   require_dependency "voter"
4   require_dependency "vote"
5   require_dependency "election"
6
7   def index
8     if params[:urlpassword]
9       password = params[:urlpassword]
10     else
11       password = nil
12     end
13
14     if @voter = FullVoter.find(:all, :conditions =>
15                                        [ "password = ?", password ] )[0]
16       @voter.vote = Vote.new if @voter.vote.nil?
17       @voter.vote.set_defaults! if @voter.vote.rankings.empty?
18
19       @election = @voter.election
20       @sidebar_content = render_to_string(:partial => 'sortable_vote')
21       render :action => 'full_vote'
22     elsif params[:urlpassword] 
23       redirect_to :action => 'index'
24     end
25   end
26
27   def login
28     if params[:vote] and params[:vote][:password]
29       redirect_to votepassword_url( :action => 'index', :urlpassword => params[:vote][:password])
30     else
31       redirect_to :action => 'index'
32     end
33   end
34   
35   def review
36     if authenticate
37       @voter.vote.time = Time.now
38       @voter.vote.save
39       @voter.reload
40     else
41       redirect_to :action => 'index'
42     end
43   end
44
45   def confirm
46     if authenticate
47       @voter.vote.confirm!
48       render :action => 'thanks'
49     else
50       redirect_to :action => 'index'
51     end
52   end
53   
54   def reminder
55     if params[:email]
56       voter_array= FullVoter.find(:all, :conditions => ["email = ?", params[:email]])
57       voter_array.delete_if {|voter| voter.election.active == 0}
58       unless voter_array.empty?
59         VoterNotify.deliver_reminder(voter_array)
60       end
61       render :action => 'reminder_sent'
62     end
63   end
64   
65   
66   private
67   def authenticate
68     password = params[:id]
69     @voter = FullVoter.find(:all, :conditions => [ "password = ?", password ] )[0]
70   end
71 end
72

Benjamin Mako Hill || Want to submit a patch?