]> source.dussan.org Git - redmine.git/commitdiff
Refactor and documentation for User#find_by_login.
authorEric Davis <edavis@littlestreamsoftware.com>
Sun, 20 Jun 2010 21:40:55 +0000 (21:40 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Sun, 20 Jun 2010 21:40:55 +0000 (21:40 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3808 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user.rb

index 5d0254ee1c7637a1fb0b9e9827b9ccd92199a544..bbb3ff2ec456ae44cb271640a239bc1518db8520 100644 (file)
@@ -221,14 +221,14 @@ class User < Principal
     @notified_projects_ids = nil
     notified_projects_ids
   end
-  
-  # case-insensitive fall-over
+
+  # Find a user account by matching the exact login and then a case-insensitive
+  # version.  Exact matches will be given priority.
   def self.find_by_login(login)
     # First look for an exact match
-    user = find(:first, :conditions => ["login = ?", login])
+    user = first(:conditions => {:login => login})
     # Fail over to case-insensitive if none was found
-    user = find(:first, :conditions => ["LOWER(login) = ?", login.to_s.downcase]) if user.nil?
-    return user
+    user ||= first(:conditions => ["LOWER(login) = ?", login.to_s.downcase])
   end
 
   def self.find_by_rss_key(key)