From 293265a00b468b9d69a261fc6029922c4d1848c8 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 13 Dec 2011 21:25:37 +0000 Subject: [PATCH] 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. --- app/models/user.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 56c8890b5..08325d5b9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,9 +47,18 @@ class User < ActiveRecord::Base def self.authenticate(options) if options[:username] and options[:password] 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) elsif options[:token] - token = UserToken.where(:token => options[:token]).preload(:user).first + token = UserToken.find_by_token(options[:token]) user = token.user if token end -- 2.43.2