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
|
2018-01-11 19:04:39 +01:00
|
|
|
render json: {}, status: 401 if !valid_token?
|
2015-12-21 17:51:49 +01:00
|
|
|
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
|
2018-01-11 19:04:39 +01:00
|
|
|
request.format = "json" if !request.params[:format]
|
2016-02-19 16:59:18 +01:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|