]> source.dussan.org Git - redmine.git/commitdiff
Makes User.find_by_mail case-insensitive (password reminder #2322, repo users mapping).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 12 Dec 2008 12:07:09 +0000 (12:07 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 12 Dec 2008 12:07:09 +0000 (12:07 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2122 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user.rb
test/integration/account_test.rb
test/unit/user_test.rb

index 3722081d260376575eb52cdb35dbd5b2300a5380..ff46d97721bc836f4b448e95b17e6404d9b549b7 100644 (file)
@@ -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)
index c349200d3f7fa3e5856f964dff2d7a2ab91a33e3..c6cfd080e1c000e7606c86ed90d37ff81fd79eb7 100644 (file)
@@ -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)
index b931501a101e6cdbe1856322e89fd6d6d64f458e..319a1c2f44d6a0bb10838b05a57f516f5f554249 100644 (file)
@@ -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