In the middle of adding custom theme supports. Skin_pictures table added to store...
[selectricity-live] / app / models / full_voter.rb
index 04071a0f398555adaf1bd10b4b0a6cf25ecc243b..18062375625cb63ca68b8102b1be80b458e7b86e 100644 (file)
@@ -1,12 +1,42 @@
+# Selectricity: Voting Machinery for the Masses
+# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
+# Copyright (C) 2007 Massachusetts Institute of Technology
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+
 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

Benjamin Mako Hill || Want to submit a patch?