demarches-normaliennes/app/controllers/api_controller.rb
2016-11-14 17:33:45 +01:00

22 lines
No EOL
476 B
Ruby

class APIController < ApplicationController
before_action :authenticate_user
before_action :default_format_json
def authenticate_user
render json: {}, status: 401 unless valid_token?
end
protected
def valid_token?
!current_administrateur.nil?
end
def current_administrateur
@administrateur ||= Administrateur.find_by_api_token(params[:token])
end
def default_format_json
request.format = "json" unless request.params[:format]
end
end