From a0a1c8d1f9791047d3f72b6770571bd793801d85 Mon Sep 17 00:00:00 2001 From: robcolbert Date: Thu, 4 Jul 2019 13:50:51 -0400 Subject: [PATCH] add ability to log in w/username or email address accepts: @user, user, user@domain.com --- app/models/user.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index eb1a2fec..ed2ce0ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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