cartodb/app/controllers/superadmin/superadmin_controller.rb

36 lines
968 B
Ruby
Raw Normal View History

2020-06-15 10:58:47 +08:00
class Superadmin::SuperadminController < ActionController::Base
before_filter :authenticate
rescue_from StandardError, with: :rescue_from_superadmin_error
def self.ssl_required(*splat)
if Rails.env.production? || Rails.env.staging?
force_ssl only: splat
end
end
def self.ssl_allowed(*_splat)
# noop
end
protected
def authenticate
return true if Rails.env.development? || authenticated?(CartoDB.extract_subdomain(request)) && current_user.admin
authenticate_or_request_with_http_basic do |username, password|
username == Cartodb.config[:superadmin]["username"] && password == Cartodb.config[:superadmin]["password"]
end
end
def current_user
super(CartoDB.extract_subdomain(request))
end
private
def rescue_from_superadmin_error(error)
CartoDB::Logger.error(exception: error)
render(json: { errors: { message: error.inspect, backtrace: error.backtrace.inspect } }, status: 500)
end
end