X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/1620856a8a47219f3a2cbb5288137b11467886fc..b6c33d42dd37f1fb10db479c5d6b7fb4c660beb9:/app/models/full_voter.rb diff --git a/app/models/full_voter.rb b/app/models/full_voter.rb index 980fb5c..68b3d07 100644 --- a/app/models/full_voter.rb +++ b/app/models/full_voter.rb @@ -1,7 +1,18 @@ +# Selectricity: Voting Machinery for the Masses +# Copyright (C) 2007, 2008 Benjamin Mako Hill +# Copyright (C) 2007 Massachusetts Institute of Technology +# +# This program is free software. Please see the COPYING file for +# details. + 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 +20,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