Module: DeviseTokenAuth::Concerns::ResourceFinder

Extended by:
ActiveSupport::Concern
Includes:
DeviseTokenAuth::Controllers::Helpers
Included in:
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



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

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

#get_case_insensitive_field_from_resource_params(field) ⇒ Object



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

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



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

def provider
  'email'
end

#resource_class(m = nil) ⇒ Object



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

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

  mapping.to
end