diff options
| author | Henare Degan <henare.degan@gmail.com> | 2013-01-25 14:40:11 +1100 | 
|---|---|---|
| committer | Henare Degan <henare.degan@gmail.com> | 2013-01-25 14:59:44 +1100 | 
| commit | 1f932b82dd4f3564f3173ab337e924c31b88717d (patch) | |
| tree | cf07ed345d5c286f8f67d8bb115384573ab43e80 | |
| parent | 55b730af6bccf8f7b08111ba9055fd8210b3a3b1 (diff) | |
User model - Overwriting validate is deprecated in Rails 3
| -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 6e1e21481..617b51c60 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 @@ -108,15 +110,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) @@ -413,6 +406,15 @@ class User < ActiveRecord::Base          self.salt = self.object_id.to_s + rand.to_s      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? | 
