Sha256: 82664bc2a1f62173dd877b78249fcc7a1f959e4fcd339f51d9288426f1909e60

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module DeviseTokenAuth::Concerns::ResourceFinder
  extend ActiveSupport::Concern
  include DeviseTokenAuth::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]

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

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

    q_value
  end

  def find_resource(field, value)
    # fix for mysql default case insensitivity
    q = "#{field.to_s} = ? AND provider='#{provider.to_s}'"
    if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql'
      q = "BINARY " + q
    end

    @resource = resource_class.where(q, value).first
  end

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

    mapping.to
  end

  def provider
    'email'
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
devise_token_auth-0.1.43 app/controllers/devise_token_auth/concerns/resource_finder.rb
digix_devise_token_auth-0.1.44 app/controllers/devise_token_auth/concerns/resource_finder.rb