diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-25 16:10:14 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-25 16:10:14 +0200 |
commit | 9d92433a7c83432657faf4c02839bba1ba6f22ac (patch) | |
tree | 1b3ab9210534b9074d35b7307cc1801dc870e548 /app/models/user.rb | |
parent | 1496c01521b46265660de72209fd81b585639bcf (diff) | |
download | gitlab-ce-9d92433a7c83432657faf4c02839bba1ba6f22ac.tar.gz |
login with both email or username
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index c73353bf032..16d91675271 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -46,6 +46,13 @@ class User < ActiveRecord::Base attr_accessor :force_random_password + # Virtual attribute for authenticating by either username or email + attr_accessor :login + + # Add login to attr_accessible + attr_accessible :login + + # # Relations # @@ -140,6 +147,16 @@ class User < ActiveRecord::Base # Class methods # class << self + # Devise method overriden to allow sing in with email or username + def find_for_database_authentication(warden_conditions) + conditions = warden_conditions.dup + if login = conditions.delete(:login) + where(conditions).where(["lower(username) = :value OR lower(email) = :value", { value: login.downcase }]).first + else + where(conditions).first + end + end + def filter filter_name case filter_name when "admins"; self.admins |