]> projects.mako.cc - selectricity-live/blob - app/controllers/voter_controller.rb
d2529f8762416927e7775776ef16ae6f0c6fb6f2
[selectricity-live] / app / controllers / voter_controller.rb
1 class VoterController < ApplicationController
2   layout 'vb'
3   model :voter
4   model :vote
5   model :election
6
7   def index
8     password = params[:id]
9     password = params[:vote][:password] if params[:vote]
10     if @voter = FullVoter.find_all( [ "password = ?", password ] )[0]
11       render :action => 'fullvote'
12     end
13   end
14   
15   def review
16     if authenticate
17       # remove any existing votes and reload
18       if @voter.vote
19         @voter.vote.destroy
20         @voter.reload
21       end
22     
23       @vote = Vote.new
24       @voter.vote = @vote
25       @vote.votestring = params[:vote][:votestring] 
26       @vote.save
27     else
28       redirect_to :action => 'index'
29     end
30   end
31
32   def confirm
33     if params[:votename]
34       if Voter.find_all( ["session_id = ?", session.session_id ])[0]
35         flash[:notice] = "You have already voted!"
36         redirect_to quickvote_url( :votename => params[:votename] )
37       else
38         @voter = QuickVoter.new()
39         @voter.election = Election.find_all( [ "name = ?",
40                                                params[:votename] ] )[0]
41         @voter.session_id = session.session_id
42         @voter.save
43         @voter.reload
44         
45         @voter.vote = Vote.new
46         @voter.vote.votestring = params[:vote][:votestring]
47         @voter.vote.save
48         @voter.vote.confirm!
49         render :action => 'thanks'
50       end
51       
52     elsif authenticate
53       @voter.vote.confirm!
54       render :action => 'thanks'
55     else
56       redirect_to :action => 'index'
57     end
58   end
59
60   def quickvote
61     @voter = QuickVoter.new
62     @voter.election = Election.find_all( [ "name = ?", params[:votename] ] )[0]
63   end
64
65   private
66   def authenticate
67     password = params[:id]
68     @voter = FullVoter.find_all( [ "password = ?", password ] )[0]
69   end
70 end
71

Benjamin Mako Hill || Want to submit a patch?