]> projects.mako.cc - selectricity/blob - app/controllers/voter_controller.rb
252711830ac96f7796062b7ab523cf391ed1eab3
[selectricity] / app / controllers / voter_controller.rb
1 class VoterController < ApplicationController
2   model :voter
3   model :vote
4   model :election
5
6   def index
7     password = params[:id]
8     password = params[:vote][:password] if params[:vote]
9     if @voter = Voter.find_all( [ "password = ?", password ] )[0]
10       render :action => 'vote'
11     end
12   end
13   
14   def review
15     if authenticate
16       # remove any existing votes and reload
17       if @voter.vote
18         @voter.vote.destroy
19         @voter.reload
20       end
21     
22       @vote = Vote.new
23       @voter.vote = @vote
24       @vote.votestring = params[:vote][:votestring] 
25       @vote.save
26     else
27       redirect_to :action => 'index'
28     end
29   end
30
31   def confirm
32     if authenticate
33       @voter.vote.confirm!
34       render :action => 'thanks'
35     else
36       redirect_to :action => 'index'
37     end
38   end
39
40   private
41   def authenticate
42     password = params[:id]
43     @voter = Voter.find_all( [ "password = ?", password ] )[0]
44   end
45 end

Benjamin Mako Hill || Want to submit a patch?