diff options
author | Henare Degan <henare.degan@gmail.com> | 2012-12-12 13:57:41 +1100 |
---|---|---|
committer | Henare Degan <henare.degan@gmail.com> | 2012-12-12 15:28:14 +1100 |
commit | b8634f8d7caa13d44a0beec2978b270964714dab (patch) | |
tree | 65f3ba604dcc0859e8a6f4a4783ebd40ff97015c | |
parent | 6e63699743941457962d53827e683fc085555aae (diff) |
Overwriting validate in your models has been deprecated
-rw-r--r-- | app/models/user.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index dba04a30a..a2815063d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -50,6 +50,8 @@ class User < ActiveRecord::Base 'super', ], :message => N_('Admin level is not included in list') + validate :email_and_name_are_valid + acts_as_xapian :texts => [ :name, :about_me ], :values => [ [ :created_at_numeric, 1, "created_at", :number ] # for sorting @@ -100,15 +102,6 @@ class User < ActiveRecord::Base self.comments.find(:all, :conditions => 'visible') end - def validate - if self.email != "" && !MySociety::Validate.is_valid_email(self.email) - errors.add(:email, _("Please enter a valid email address")) - end - if MySociety::Validate.is_valid_email(self.name) - errors.add(:name, _("Please enter your name, not your email address, in the name field.")) - end - end - # Don't display any leading/trailing spaces # XXX we have strip_attributes! now, so perhaps this can be removed (might # be still needed for existing cases) @@ -416,6 +409,15 @@ class User < ActiveRecord::Base end end + def email_and_name_are_valid + if self.email != "" && !MySociety::Validate.is_valid_email(self.email) + errors.add(:email, _("Please enter a valid email address")) + end + if MySociety::Validate.is_valid_email(self.name) + errors.add(:name, _("Please enter your name, not your email address, in the name field.")) + end + end + ## Class methods def User.encrypted_password(password, salt) string_to_hash = password + salt # XXX need to add a secret here too? |