Module: DeviseTokenAuth::Concerns::ResourceFinder

Extended by:
ActiveSupport::Concern
Includes:
DeviseTokenAuth::Controllers::Helpers
Included in:
ApplicationController, SetUserByToken
Defined in:
app/controllers/devise_token_auth/concerns/resource_finder.rb

Instance Method Summary collapse

Methods included from DeviseTokenAuth::Controllers::Helpers

define_helpers

Instance Method Details

#find_resource(field, value) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/controllers/devise_token_auth/concerns/resource_finder.rb', line 20

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

#get_case_insensitive_field_from_resource_params(field) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/devise_token_auth/concerns/resource_finder.rb', line 5

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

#providerObject



40
41
42
# File 'app/controllers/devise_token_auth/concerns/resource_finder.rb', line 40

def provider
  'email'
end

#resource_class(m = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/controllers/devise_token_auth/concerns/resource_finder.rb', line 30

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