Strip leading and trailing whitespace for email authentication
authorTom Hughes <tom@compton.nu>
Fri, 8 Mar 2019 10:58:42 +0000 (10:58 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 8 Mar 2019 10:59:57 +0000 (10:59 +0000)
Fixes #2173

app/models/user.rb

index 27ed7b6..25947a9 100644 (file)
@@ -122,10 +122,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