Sha256: e9386220d49e6e29f95ebf542f2081dfc4eefccae79fdb6397dbd97274b32ed9
Contents?: true
Size: 1017 Bytes
Versions: 15
Compression:
Stored size: 1017 Bytes
Contents
module Challah module UserFindable extend ActiveSupport::Concern included do extend ClassMethods end module ClassMethods def active where(active: true) end # Find a user instance by username first, or email address if needed. # If no user is found matching, return nil def find_for_session(username_or_email) return if username_or_email.to_s.blank? username_or_email = username_or_email.downcase.strip find_by_email(username_or_email) || find_by_authorization(username_or_email) end def inactive where.not(active: true) end protected def find_by_authorization(uid) authorization = self.authorization_model result = authorization.where(provider: :password, uid: uid).first if result result.user end end def find_by_email(email) return unless email.include?('@') where(email: email).first end end end end
Version data entries
15 entries across 15 versions & 1 rubygems