Look up names and emails case insensitively for authentication

If the name entered is not found then try a case insensitive lookup
and if that finds a single result then use it.
This commit is contained in:
Tom Hughes 2011-12-13 21:25:37 +00:00
parent b705af948b
commit 293265a00b

View file

@ -47,9 +47,18 @@ class User < ActiveRecord::Base
def self.authenticate(options) def self.authenticate(options)
if options[:username] and options[:password] if options[:username] and options[:password]
user = where("email = ? OR display_name = ?", options[:username], options[:username]).first user = where("email = ? OR display_name = ?", options[:username], options[:username]).first
if user.nil?
users = where("LOWER(email) = LOWER(?) OR LOWER(display_name) = LOWER(?)", options[:username], options[:username])
if users.count == 1
user = users.first
end
end
user = nil if user and user.pass_crypt != OSM::encrypt_password(options[:password], user.pass_salt) user = nil if user and user.pass_crypt != OSM::encrypt_password(options[:password], user.pass_salt)
elsif options[:token] elsif options[:token]
token = UserToken.where(:token => options[:token]).preload(:user).first token = UserToken.find_by_token(options[:token])
user = token.user if token user = token.user if token
end end