Sha256: ed4a5b03a1574a1c72464229e1070b733d0d9768dfbf42b06e3396458c98e391

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module DeviseJwtAuth::Concerns::ResourceFinder
  extend ActiveSupport::Concern
  include DeviseJwtAuth::Controllers::Helpers

  def get_case_insensitive_field_from_resource_params(field)
    # honor Devise configuration for case_insensitive keys
    q_value = resource_params[field.to_sym]

    q_value.downcase! if resource_class.case_insensitive_keys.include?(field.to_sym)

    q_value.strip! if resource_class.strip_whitespace_keys.include?(field.to_sym)

    q_value
  end

  def find_resource(field, value)
    @resource = if resource_class.try(:connection_config).try(:[], :adapter).try(:include?, 'mysql')
                  # fix for mysql default case insensitivity
                  resource_class.where("BINARY #{field} = ? AND provider= ?", value, provider).first
                else
                  resource_class.dta_find_by(field => value, 'provider' => provider)
                end
  end

  def resource_class(m = nil)
    mapping = if m
                Devise.mappings[m]
              else
                Devise.mappings[resource_name] || Devise.mappings.values.first
              end

    mapping.to
  end

  def provider
    'email'
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
devise_jwt_auth722-0.1.7 app/controllers/devise_jwt_auth/concerns/resource_finder.rb
devise_jwt_auth7-0.1.7 app/controllers/devise_jwt_auth/concerns/resource_finder.rb
devise_jwt_auth-0.1.7 app/controllers/devise_jwt_auth/concerns/resource_finder.rb
devise_jwt_auth-0.1.6 app/controllers/devise_jwt_auth/concerns/resource_finder.rb