mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
41 lines
936 B
Ruby
41 lines
936 B
Ruby
module Api
|
|
module Admin
|
|
class ApplicationController < ActionController::API
|
|
include ActionController::HttpAuthentication::Token::ControllerMethods
|
|
|
|
before_action :authenticate_admin_api_key!
|
|
|
|
private
|
|
|
|
def authenticate_admin_api_key!
|
|
authenticate_or_request_with_http_token do |token, options|
|
|
@admin_api_key = AdminApiKey.active.find_by(token: token)
|
|
|
|
if @admin_api_key
|
|
@current_user = @admin_api_key.user
|
|
@current_user.admin?
|
|
else
|
|
false
|
|
end
|
|
end
|
|
end
|
|
|
|
def current_user
|
|
@current_user
|
|
end
|
|
|
|
def current_admin_api_key
|
|
@admin_api_key
|
|
end
|
|
|
|
def render_unauthorized
|
|
render json: { error: "lmao no perms" }, status: :unauthorized
|
|
end
|
|
|
|
def render_forbidden
|
|
render json: { error: "lmao no perms" }, status: :forbidden
|
|
end
|
|
end
|
|
end
|
|
end
|