add ability to log in w/username or email address

accepts:
@user, user, user@domain.com
This commit is contained in:
robcolbert 2019-07-04 13:50:51 -04:00
parent f30e96221d
commit a0a1c8d1f9
1 changed files with 10 additions and 0 deletions

View File

@ -327,4 +327,14 @@ class User < ApplicationRecord
def validate_email_dns?
email_changed? && !(Rails.env.test? || Rails.env.development?)
end
# allow username or email address for login (Gab)
def self.find_for_database_authentication conditions
if conditions[:email].start_with? "@" or !conditions[:email].include? "@"
joins(:account).find_by(accounts: { domain: nil, username: conditions[:email].sub('@', '') })
else
super
end
end
end