Strip leading and trailing whitespace for email authentication

Fixes #2173
This commit is contained in:
Tom Hughes 2019-03-08 10:58:42 +00:00
parent b7834aa827
commit e174eb762f

View file

@ -122,10 +122,10 @@ class User < ActiveRecord::Base
def self.authenticate(options) def self.authenticate(options)
if options[:username] && options[:password] 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? 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 user = users.first if users.count == 1
end end