2021-07-14 13:10:24 +00:00
|
|
|
# TODO: we should switch to ActionController::API for the base classes
|
|
|
|
# One of the specs is failing when I tried doing that, lets revisit in future
|
2021-06-15 14:39:17 +00:00
|
|
|
class PublicController < ActionController::Base
|
2021-09-14 06:25:02 +00:00
|
|
|
include RequestExceptionHandler
|
2021-06-15 14:39:17 +00:00
|
|
|
skip_before_action :verify_authenticity_token
|
2022-09-07 06:52:24 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ensure_custom_domain_request
|
2022-09-20 00:36:01 +00:00
|
|
|
domain = request.host
|
2022-09-07 06:52:24 +00:00
|
|
|
|
2022-09-20 00:36:01 +00:00
|
|
|
return if [URI.parse(ENV.fetch('FRONTEND_URL', '')).host, URI.parse(ENV.fetch('HELPCENTER_URL', '')).host].include?(domain)
|
2022-09-07 06:52:24 +00:00
|
|
|
|
2022-09-20 00:36:01 +00:00
|
|
|
@portal = ::Portal.find_by(custom_domain: domain)
|
|
|
|
return if @portal.present?
|
2022-09-07 06:52:24 +00:00
|
|
|
|
|
|
|
render json: {
|
2022-09-20 00:36:01 +00:00
|
|
|
error: "Domain: #{domain} is not registered with us. \
|
2022-09-07 06:52:24 +00:00
|
|
|
Please send us an email at support@chatwoot.com with the custom domain name and account API key"
|
|
|
|
}, status: :unauthorized and return
|
|
|
|
end
|
2021-06-15 14:39:17 +00:00
|
|
|
end
|