fixed licensing information for selectricity
[selectricity] / app / models / token.rb
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
4 #
5 # This program is free software. Please see the COPYING file for
6 # details.
7
8 class Token < ActiveRecord::Base 
9   belongs_to :vote
10   
11   def initialize
12     super
13
14     token_generator = UniqueTokenGenerator.new( 16 )
15     until token and not token.empty? \
16       and Token.find(:all, :conditions => [ "token = ?", token ]).empty? and token[0..3] != "open"
17       self.token = token_generator.token
18     end
19
20     self
21   end
22
23   def to_s
24     self.token
25   end
26 end

Benjamin Mako Hill || Want to submit a patch?