X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/75091532075247ae9c47164ea883f4fe803eddf4..1e8c21d4c4c93721c16a669e330a6d4e60483919:/app/models/full_voter.rb diff --git a/app/models/full_voter.rb b/app/models/full_voter.rb index 04071a0..9e5709e 100644 --- a/app/models/full_voter.rb +++ b/app/models/full_voter.rb @@ -1,12 +1,24 @@ class FullVoter < Voter - before_create :create_password validates_presence_of :email, :password + def initialize(params={}) + super + create_password + end + def create_password token_generator = UniqueTokenGenerator.new( 16 ) until password and not password.empty? \ - and Voter.find_all( [ "password = ?", password ]).empty? + and Voter.find(:all, :conditions => [ "password = ?", password ]).empty? self.password = token_generator.token end end + + protected + def validate + # E-mail regex, moderate complexity + # Stolen from http://www.regular-expressions.info/email.html + errors.add(:email, "is not valid") unless email =~ + /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i + end end