Sha256: ae950e69e0ee14720766a8a0cb8d91de79befb62cc1633157c74e9f1031a89fb

Contents?: true

Size: 1013 Bytes

Versions: 2

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true

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)
    attrs = { field => value, 'provider' => provider }
    @resource = resource_class.dta_find_by(attrs, self.instance_eval(&DeviseTokenAuth.multitenancy_finder_params))
  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

2 entries across 2 versions & 1 rubygems

Version Path
devise_token_auth_multitenancy-1.1.3.2 app/controllers/devise_token_auth/concerns/resource_finder.rb
devise_token_auth_multitenancy-1.1.3.1 app/controllers/devise_token_auth/concerns/resource_finder.rb