]> projects.mako.cc - selectricity-live/blobdiff - app/models/full_voter.rb
merged in changes from devel
[selectricity-live] / app / models / full_voter.rb
index 980fb5cf3c0fdeef0c043be9aeabe33233f6a874..9e5709eb77d96c78c67ca050e497a6f92255b93a 100644 (file)
@@ -1,7 +1,11 @@
 class FullVoter < Voter
 class FullVoter < Voter
-  before_create :create_password
   validates_presence_of :email, :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? \
   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
       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
 end

Benjamin Mako Hill || Want to submit a patch?