module Challah::UserFindable::ClassMethods

Public Instance Methods

find_for_session(username_or_email) click to toggle source

Find a user instance by username first, or email address if needed. If no user is found matching, return nil

# File lib/challah/concerns/user/findable.rb, line 9
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

Protected Instance Methods

find_by_authorization(uid) click to toggle source
# File lib/challah/concerns/user/findable.rb, line 18
def find_by_authorization(uid)
  authorization = self.authorization_model
  result = authorization.where(provider: :password, uid: uid).first
  if result
    result.user
  end
end
find_by_email(email) click to toggle source
# File lib/challah/concerns/user/findable.rb, line 26
def find_by_email(email)
  return unless email.include?('@')
  where(email: email).first
end