diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/about_me_validator.rb | 20 | ||||
-rw-r--r-- | app/models/user.rb | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb new file mode 100644 index 000000000..70778d911 --- /dev/null +++ b/app/models/about_me_validator.rb @@ -0,0 +1,20 @@ +# models/about_me_validator.rb: +# Validates editing about me text on user profile pages. +# +# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $ + +class AboutMeValidator < ActiveRecord::BaseWithoutTable + strip_attributes! + + column :about_me, :text, "I...", false + + def validate + if !self.about_me.blank? && self.about_me.size > 500 + errors.add(:about_me, "^Please keep it shorter than 500 characters") + end + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index dcc92d5e3..8b99cb61e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -109,6 +109,8 @@ class User < ActiveRecord::Base 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) def name name = read_attribute(:name) if not name.nil? @@ -308,6 +310,16 @@ class User < ActiveRecord::Base nil # so doesn't print all users on console end + # Return about me text for display as HTML + def get_about_me_for_html_display + text = self.about_me.strip + text = CGI.escapeHTML(text) + text = MySociety::Format.make_clickable(text, :contract => 1) + text = text.gsub(/\n/, '<br>') + return text + end + + private def User.encrypted_password(password, salt) |