2019-08-14 09:48:44 +00:00
|
|
|
class Api::BaseController < ApplicationController
|
2020-03-10 18:32:15 +00:00
|
|
|
include AccessTokenAuthHelper
|
2019-08-14 09:48:44 +00:00
|
|
|
respond_to :json
|
2020-03-10 18:32:15 +00:00
|
|
|
before_action :authenticate_access_token!, if: :authenticate_by_access_token?
|
|
|
|
before_action :validate_bot_access_token!, if: :authenticate_by_access_token?
|
|
|
|
before_action :authenticate_user!, unless: :authenticate_by_access_token?
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-10 18:32:15 +00:00
|
|
|
def authenticate_by_access_token?
|
2020-04-07 04:49:19 +00:00
|
|
|
request.headers[:api_access_token].present? || request.headers[:HTTP_API_ACCESS_TOKEN].present?
|
2020-03-10 18:32:15 +00:00
|
|
|
end
|
2020-10-20 13:52:21 +00:00
|
|
|
|
|
|
|
def check_authorization(model = nil)
|
|
|
|
model ||= controller_name.classify.constantize
|
|
|
|
|
|
|
|
authorize(model)
|
|
|
|
end
|
2021-06-11 06:14:31 +00:00
|
|
|
|
|
|
|
def check_admin_authorization?
|
|
|
|
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|