X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/b4ef61a9f31ac8bb911c094bc2fb00a9fa2102a6..7ccf6964e30a9e0de2ab2af048c777e74883bb99:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index a57c88379..fba429338 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -93,12 +93,13 @@ class User < ActiveRecord::Base validates :display_name, :if => proc { |u| u.display_name_changed? }, :uniqueness => { :case_sensitive => false } validates :display_name, :if => proc { |u| u.display_name_changed? }, - :invalid_chars => true, - :invalid_url_chars => true, + :characters => { :url_safe => true }, :whitespace => { :leading => false, :trailing => false } - validates :email, :presence => true, :confirmation => true, :invalid_chars => true + validates :email, :presence => true, :confirmation => true, :characters => true validates :email, :if => proc { |u| u.email_changed? }, :uniqueness => { :case_sensitive => false } + validates :email, :if => proc { |u| u.email_changed? }, + :whitespace => { :leading => false, :trailing => false } validates :pass_crypt, :confirmation => true, :length => 8..255 validates :home_lat, :allow_nil => true, :numericality => true, :inclusion => { :in => -90..90 } validates :home_lon, :allow_nil => true, :numericality => true, :inclusion => { :in => -180..180 } @@ -123,10 +124,10 @@ class User < ActiveRecord::Base def self.authenticate(options) if options[:username] && options[:password] - user = find_by("email = ? OR display_name = ?", options[:username], options[:username]) + user = find_by("email = ? OR display_name = ?", options[:username].strip, options[:username]) if user.nil? - users = where("LOWER(email) = LOWER(?) OR LOWER(display_name) = LOWER(?)", options[:username], options[:username]) + users = where("LOWER(email) = LOWER(?) OR LOWER(display_name) = LOWER(?)", options[:username].strip, options[:username]) user = users.first if users.count == 1 end