fixed colors on graphs
[selectricity-live] / app / models / full_voter.rb
1 class FullVoter < Voter
2   validates_presence_of :email, :password
3
4   def initialize(params={})
5     super
6     create_password
7   end
8   
9   def create_password
10     token_generator = UniqueTokenGenerator.new( 16 )
11     until password and not password.empty? \
12           and Voter.find(:all, :conditions => [ "password = ?", password ]).empty?
13       self.password = token_generator.token
14     end
15   end
16   
17   protected
18   def validate
19     # E-mail regex, moderate complexity
20     # Stolen from http://www.regular-expressions.info/email.html
21     errors.add(:email, "is not valid") unless email  =~
22                   /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
23   end
24 end

Benjamin Mako Hill || Want to submit a patch?