Sha256: abda7214fc35418b42c4c42f16d9ee59200c6ea3522e4e6b08b25811613ab91f

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

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

  before_action :authenticate_user

  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

<% if !options.fbonly? %> 
    def authenticate_password
      if current_user.nil?
        return true
      end
      if !current_user.authenticate(params[:user][:password]) 
        return true
      else
        return false
      end
    end
<% end %>

    def set_hash
      #["current_owner","current_token"] Make this true to check for email also
      @instance_hash = ::Arcadex::Authentication.get_instance(params,request,"Auth-Token")
      #@instance_hash = ::Arcadex::Authentication.authenticate_owner_with_index(params,request,"Auth-Token","Email","email",true)
      #Ignore the token if the user's account is locked
      <% if !options.fbonly? %> 
      if !current_user.nil? && current_user.locked
        @instance_hash = nil
      end
      <% end %>
    end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_voorhees-1.4.1 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
json_voorhees-1.4.0 lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb