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

Version Path
challah-1.3.3 lib/challah/concerns/user/findable.rb
challah-1.3.2 lib/challah/concerns/user/findable.rb
challah-1.3.1 lib/challah/concerns/user/findable.rb
challah-1.3.0 lib/challah/concerns/user/findable.rb
challah-1.2.11 lib/challah/concerns/user/findable.rb
challah-1.2.10 lib/challah/concerns/user/findable.rb
challah-1.2.9 lib/challah/concerns/user/findable.rb
challah-1.2.8 lib/challah/concerns/user/findable.rb
challah-1.2.7 lib/challah/concerns/user/findable.rb
challah-1.2.6 lib/challah/concerns/user/findable.rb
challah-1.2.5 lib/challah/concerns/user/findable.rb
challah-1.2.5.pre lib/challah/concerns/user/findable.rb
challah-1.2.4 lib/challah/concerns/user/findable.rb
challah-1.2.3 lib/challah/concerns/user/findable.rb
challah-1.2.2 lib/challah/concerns/user/findable.rb