From 47df83c4f73a57433cb68f680d094bced429cff5 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 20 Apr 2012 10:58:31 +0200 Subject: [PATCH] Improved login wording (Username or email). Added functionality. --- .../javascripts/app/views/login.jst.eco | 4 ++-- app/models/user.rb | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/views/login.jst.eco b/app/assets/javascripts/app/views/login.jst.eco index e4a345d1c..a8415287c 100644 --- a/app/assets/javascripts/app/views/login.jst.eco +++ b/app/assets/javascripts/app/views/login.jst.eco @@ -8,9 +8,9 @@
Sign in with
diff --git a/app/models/user.rb b/app/models/user.rb index 2e32bc924..b1b328e9e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,10 +13,27 @@ class User < ApplicationModel store :preferences def self.authenticate( username, password ) + + # try to find user based on login user = User.where( :login => username, :active => true ).first - return nil if user.nil? - return user if user.password == password - return + + # try second lookup with email + if !user + user = User.where( :email => username, :active => true ).first + end + + # no user found + if !user + return nil + end + + # auth ok + if user.password == password + return user + end + + # auth failed + return false end def self.create_from_hash!(hash)