Sha256: c6b0f37df225efbe98e5197c9bc25b5dd1755452993c1fad9f73ff628c29dd61

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

module DeviseTokenAuth
  class ApplicationController < DeviseController
    include DeviseTokenAuth::Concerns::SetUserByToken

    def resource_data(opts={})
      response_data = opts[:resource_json] || @resource.as_json
      if is_json_api
        response_data['type'] = @resource.class.name.parameterize
      end
      response_data
    end

    def resource_errors
      return @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
    end

    protected

    def params_for_resource(resource)
      devise_parameter_sanitizer.instance_values['permitted'][resource].each do |type|
        params[type.to_s] ||= request.headers[type.to_s] unless request.headers[type.to_s].nil?
      end
      devise_parameter_sanitizer.instance_values['permitted'][resource]
    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 is_json_api
      return false unless defined?(ActiveModel::Serializer)
      return ActiveModel::Serializer.setup do |config|
        config.adapter == :json_api
      end if ActiveModel::Serializer.respond_to?(:setup)
      return ActiveModelSerializers.config.adapter == :json_api
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
devise_token_auth-0.1.42 app/controllers/devise_token_auth/application_controller.rb
devise_token_auth-0.1.41 app/controllers/devise_token_auth/application_controller.rb
devise_token_auth-0.1.40 app/controllers/devise_token_auth/application_controller.rb
devise_token_auth-0.1.39 app/controllers/devise_token_auth/application_controller.rb
devise_token_auth-0.1.38 app/controllers/devise_token_auth/application_controller.rb