Sha256: c0c8a6cf561a3dc325413cd21601e2f59882858b3d4f6fcbc1a554685613152b

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

class Api::V1::ApiController < ::ActionController::API

  before_action :authenticate_user
  after_filter :cors_set_access_control_headers
  skip_before_filter :authenticate_user, :only => [:route_options]

  def route_options
    cors_preflight_check
  end

  private

    def authenticate_user
      set_hash
      if @instance_hash.nil?
        render :json => {errors: "User is not logged in, register or log in"} , status: :unauthorized
      end
    end

    def set_hash
      #["current_user","current_token"] Make this true to check for email also
      @instance_hash = ::Arcadex::Authentication.full_authentication(params,request,false)
    end

    def current_user
      if !@instance_hash.nil?
        return @instance_hash["current_user"]
      else
        return nil
      end
    end

    def current_token
      if !@instance_hash.nil?
        return @instance_hash["current_token"]
      else
        return nil
      end
    end

    def cors_set_access_control_headers
      response.headers['Access-Control-Allow-Origin'] = '*'
      response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
      response.headers['Access-Control-Allow-Headers'] = '*, Origin, Content-Type, Accept, Authorization, Token, Auth-Token, Email'
      response.headers['Access-Control-Expose-Headers'] = '*'
      response.headers['Access-Control-Max-Age'] = "1728000"
    end
     
    def cors_preflight_check
      #if request.method == 'OPTIONS'
        request.headers['Access-Control-Allow-Origin'] = '*'
        request.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
        request.headers['Access-Control-Allow-Headers'] = '*, X-Requested-With, X-Prototype-Version, Token, Auth-Token, Email'
        request.headers['Access-Control-Max-Age'] = '1728000'  
        render :text => '', :content_type => 'text/plain'
      #end
    end
    
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
json_voorhees-0.5.5 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
json_voorhees-0.5.4 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
json_voorhees-0.5.3 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
json_voorhees-0.5.2 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
json_voorhees-0.5.1 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb