Look up email addresses case insensitively for password resets
authorTom Hughes <tom@compton.nu>
Tue, 13 Dec 2011 17:42:42 +0000 (17:42 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 13 Dec 2011 17:42:42 +0000 (17:42 +0000)
If the email address entered is not found then try a case insensitive
lookup, and if that finds a single result then use it.

app/controllers/user_controller.rb

index ce0122957dfc1083629372752d7e01191ebd3c1a..c9983cc855807f1fa343ecc1fedc4a5909bb8468 100644 (file)
@@ -201,7 +201,15 @@ class UserController < ApplicationController
     @title = t 'user.lost_password.title'
 
     if params[:user] and params[:user][:email]
-      user = User.visible.where(:email => params[:user][:email]).first
+      user = User.visible.find_by_email(params[:user][:email])
+
+      if user.nil?
+        users = User.visible.where("LOWER(email) = LOWER(?)", params[:user][:email])
+
+        if users.count == 1
+          user = users.first
+        end
+      end
 
       if user
         token = user.tokens.create