X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/9086b07aefc0560832373bb4ba30888d8d43f0d6..d66a99486376939d64f8a5d9032dcc516f7b1195:/app/models/full_voter.rb?ds=sidebyside diff --git a/app/models/full_voter.rb b/app/models/full_voter.rb index 980fb5c..9e5709e 100644 --- a/app/models/full_voter.rb +++ b/app/models/full_voter.rb @@ -1,7 +1,11 @@ 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? \ @@ -9,4 +13,12 @@ class FullVoter < Voter 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