class VoterController < ApplicationController
+ layout 'vb'
model :voter
model :vote
model :election
def index
password = params[:id]
password = params[:vote][:password] if params[:vote]
- if @voter = Voter.find_all( [ "password = ?", password ] )[0]
- render :action => 'vote'
+ if @voter = FullVoter.find_all( [ "password = ?", password ] )[0]
+ render :action => 'fullvote'
end
end
end
def confirm
- if authenticate
+ if params[:votename]
+ if Voter.find_all( ["session_id = ?", session.session_id ])[0]
+ flash[:notice] = "You have already voted!"
+ redirect_to quickvote_url( :votename => params[:votename] )
+ else
+ @voter = QuickVoter.new()
+ @voter.election = Election.find_all( [ "name = ?",
+ params[:votename] ] )[0]
+ @voter.session_id = session.session_id
+ @voter.save
+ @voter.reload
+
+ @voter.vote = Vote.new
+ @voter.vote.votestring = params[:vote][:votestring]
+ @voter.vote.save
+ @voter.vote.confirm!
+ render :action => 'thanks'
+ end
+
+ elsif authenticate
@voter.vote.confirm!
render :action => 'thanks'
else
end
end
+ def quickvote
+ @voter = QuickVoter.new
+ @voter.election = Election.find_all( [ "name = ?", params[:votename] ] )[0]
+ end
+
private
def authenticate
password = params[:id]
- @voter = Voter.find_all( [ "password = ?", password ] )[0]
+ @voter = FullVoter.find_all( [ "password = ?", password ] )[0]
end
end
+
def activate!
self.active = 1
end
+
+ def quickvote?
+ quickvote.to_i == 1
+ end
end
--- /dev/null
+class FullVoter < Voter
+ before_create :create_password
+ validates_presence_of :email, :password
+
+ def create_password
+ token_generator = UniqueTokenGenerator.new( 16 )
+ until password and not password.empty? \
+ and Voter.find_all( [ "password = ?", password ]).empty?
+ self.password = token_generator.token
+ end
+ end
+end
self.enddate = DateTime.now + 30
self.active = 1
self.anonymous = 1
+ self.quickvote = 1
end
def candidatelist=(candstring='')
end
def reviewed?
- if reviewed.to_i == 1
- return true
- else
- false
- end
+ reviewed.to_i == 1
end
def create_candidates
--- /dev/null
+class QuickVoter < Voter
+ validates_presence_of :session_id
+ validates_uniqueness_of :session_id
+end
def confirm!
self.confirmed = 1
self.save
-
- token.destroy and token.reload if token
- self.token = Token.new
- self.save
+
+ unless self.voter.election.quickvote?
+ token.destroy and token.reload if token
+ self.token = Token.new
+ self.save
+ end
end
def confirm?
- if confirm == 1
- return true
- else
- return false
- end
+ confirmed == 1
end
def votestring=(string="")
belongs_to :election
has_one :vote
- before_create :create_password
-
- def create_password
- token_generator = UniqueTokenGenerator.new( 16 )
- until password and not password.empty? \
- and Voter.find_all( [ "password = ?", password ]).empty?
- self.password = token_generator.token
- end
- end
-
end
of preferential and non-preficial election methods, or to compare
between methods.</p>
-<p><%= link_to "Create QuickVote.", :action => 'create_quickvote' %></p>
+<p><%= link_to "Create QuickVote.", :controller => 'quickvote', :action => 'create' %></p>
<h2>Voters</h2>
participate in this election.</p>
<p>Direct voters to:</p>
-<blockquote><strong><%= url_for :action => 'quickvote', :id => @quickvote.id, :only_path => false %></strong></blockquote>
+<blockquote><strong><%= quickvote_url( :votename => @quickvote.name ) %></strong></blockquote>
<p>This vote will expire on <em><%= @quickvote.enddate %></em></p>
+<p><%= link_to "Visit in or vote in your QuickVote", quickvote_url( :votename => @quickvote.name ) %></p>
--- /dev/null
+<% %>
+
+<% if @voter.election.quickvote? %>
+ <h1>QuickVote: <em><%= @voter.election.name %></em></h1>
+ <p><strong>Description:</strong></p>
+ <blockquote><%= @voter.election.description %></blockquote>
+<% else %>
+ <p><strong>Election:</strong> <%= @voter.election.name %></p>
+ <p><strong>Voter:</strong> <%= @voter.email %></p>
+ <p><strong>Description:</strong></p>
+ <blockquote><%= @voter.election.description %></blockquote>
+<% end %>
+
+<p><strong>Candidates:</strong></p>
+<ol>
+<% for candidate in @voter.election.candidates.sort %>
+ <li><%= candidate.name %></li>
+<% end %>
+</ol>
+
+<hr />
+
+<h2>Place Your Vote Here</h2>
+
+<p>Rank each candidate in order of more preferred to least
+preferred. (e.g., 123 or 321 or 213, etc.)</p>
+
+<% if @voter.election.quickvote? %>
+ <%= form_tag quickconfirm_url( :votename => @voter.election.name ) %>
+<% else %>
+ <%= form_tag :action => 'review', :id => @voter.password %>
+<% end %>
+
+<%= text_field :vote, :votestring -%>
+<%= submit_tag "Submit!" %>
+<%= end_form_tag %>
+
--- /dev/null
+<% %>
+
+<%= render_partial 'vote' %>
+
+
--- /dev/null
+<% %>
+<%= render_partial 'vote' %>
+++ /dev/null
-<% %>
-
-<h1>Vote Below the Line</h1>
-
-<p><strong>Election:</strong> <%= @voter.election.name %></p>
-
-<p><strong>Voter:</strong> <%= @voter.email %></p>
-
-<p><strong>Candidates:</strong></p>
-
-<ol>
-<% for candidate in @voter.election.candidates.sort %>
- <li><%= candidate.name %></li>
-<% end %>
-</ol>
-
-<p>If this information is incorrect, please notify the vote
-administrator immediatedly!</p>
-
-<hr />
-
-<h2>Place Your Vote Here</h2>
-
-<p>Rank each candidate in order of more preferred to least
-preferred. (e.g., 123 or 321 or 213, etc.)</p>
-
-<%= form_tag :action => 'review', :id => @voter.password %>
-<%= text_field :vote, :votestring -%>
-<%= submit_tag "Submit!" %>
-<%= end_form_tag %>
-
-
-
-
-
# -- just remember to delete public/index.html.
map.connect '', :controller => "site"
+ map.connect 'quickvote/create',
+ :controller => 'site',
+ :action => 'create_quickvote'
+
+ map.quickconfirm 'quickvote/:votename/confirm',
+ :controller => 'voter',
+ :action => 'confirm'
+
+ map.quickvote 'quickvote/:votename',
+ :controller => 'voter',
+ :action => 'quickvote'
+
# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named 'wsdl'
map.connect ':controller/service.wsdl', :action => 'wsdl'
startdate datetime,
enddate datetime NOT NULL,
active tinyint NOT NULL DEFAULT 0,
- user_id int NOT NULL,
+ user_id int NULL,
+ quickvote tinyint NOT NULL DEFAULT 0,
primary key (id),
constraint fk_user_election foreign key (user_id) references users(id)
);
drop table if exists voters;
create table voters (
id int NOT NULL auto_increment,
- email varchar(100) NOT NULL,
- password varchar(100) NOT NULL,
+ email varchar(100) NULL,
+ password varchar(100) NULL,
contacted tinyint NOT NULL DEFAULT 0,
election_id int NOT NULL,
+ session_id varchar(32) DEFAULT NULL,
constraint fk_election_voter foreign key (election_id) references election(id),
primary key (id)
);
+
# CREATE tokens TABLE
#####################################
--- /dev/null
+class CreateFullVoters < ActiveRecord::Migration
+ def self.up
+ create_table :full_voters do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :full_voters
+ end
+end
--- /dev/null
+class CreateQuickVoters < ActiveRecord::Migration
+ def self.up
+ create_table :quick_voters do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :quick_voters
+ end
+end
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+ id: 1
+another:
+ id: 2
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+ id: 1
+another:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class FullVoterTest < Test::Unit::TestCase
+ fixtures :full_voters
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class QuickVoterTest < Test::Unit::TestCase
+ fixtures :quick_voters
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end