summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/user.rb5
-rw-r--r--test/integration/account_test.rb2
-rw-r--r--test/unit/user_test.rb6
3 files changed, 12 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 3722081d2..ff46d9772 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -178,6 +178,11 @@ class User < ActiveRecord::Base
token = Token.find_by_action_and_value('autologin', key)
token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
end
+
+ # Makes find_by_mail case-insensitive
+ def self.find_by_mail(mail)
+ find(:first, :conditions => ["LOWER(mail) = ?", mail.to_s.downcase])
+ end
# Sort users by their display names
def <=>(user)
diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb
index c349200d3..c6cfd080e 100644
--- a/test/integration/account_test.rb
+++ b/test/integration/account_test.rb
@@ -44,7 +44,7 @@ class AccountTest < ActionController::IntegrationTest
assert_response :success
assert_template "account/lost_password"
- post "account/lost_password", :mail => 'jsmith@somenet.foo'
+ post "account/lost_password", :mail => 'jSmith@somenet.foo'
assert_redirected_to "account/login"
token = Token.find(:first)
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index b931501a1..319a1c2f4 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -158,4 +158,10 @@ class UserTest < Test::Unit::TestCase
@jsmith.pref.comments_sorting = 'desc'
assert @jsmith.wants_comments_in_reverse_order?
end
+
+ def test_find_by_mail_should_be_case_insensitive
+ u = User.find_by_mail('JSmith@somenet.foo')
+ assert_not_nil u
+ assert_equal 'jsmith@somenet.foo', u.mail
+ end
end