demarches-normaliennes/app/controllers/api_controller.rb

23 lines
477 B
Ruby
Raw Normal View History

2015-12-21 17:51:49 +01:00
class APIController < ApplicationController
before_action :authenticate_user
2016-11-14 17:33:45 +01:00
before_action :default_format_json
2015-12-21 17:51:49 +01:00
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
2016-02-19 16:59:18 +01:00
def default_format_json
2016-02-22 15:20:58 +01:00
request.format = "json" unless request.params[:format]
2016-02-19 16:59:18 +01:00
end
2017-04-04 15:27:04 +02:00
end