2018-12-14 05:06:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
module ActionMailbox
|
2019-01-01 16:43:03 -05:00
|
|
|
# The base class for all Action Mailbox ingress controllers.
|
2018-12-26 16:18:42 -05:00
|
|
|
class BaseController < ActionController::Base
|
|
|
|
skip_forgery_protection
|
2018-10-06 22:02:08 -04:00
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
before_action :ensure_configured
|
2018-12-24 15:16:22 -05:00
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
def self.prepare
|
|
|
|
# Override in concrete controllers to run code on load.
|
|
|
|
end
|
2018-11-05 12:39:37 -05:00
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
private
|
|
|
|
def ensure_configured
|
|
|
|
unless ActionMailbox.ingress == ingress_name
|
|
|
|
head :not_found
|
|
|
|
end
|
2018-11-05 09:11:01 -05:00
|
|
|
end
|
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
def ingress_name
|
|
|
|
self.class.name.remove(/\AActionMailbox::Ingresses::/, /::InboundEmailsController\z/).underscore.to_sym
|
|
|
|
end
|
2018-11-05 09:11:01 -05:00
|
|
|
|
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
def authenticate_by_password
|
|
|
|
if password.present?
|
|
|
|
http_basic_authenticate_or_request_with name: "actionmailbox", password: password, realm: "Action Mailbox"
|
|
|
|
else
|
|
|
|
raise ArgumentError, "Missing required ingress credentials"
|
|
|
|
end
|
2018-10-06 22:02:08 -04:00
|
|
|
end
|
2018-10-29 14:19:46 -04:00
|
|
|
|
2018-12-26 16:18:42 -05:00
|
|
|
def password
|
|
|
|
Rails.application.credentials.dig(:action_mailbox, :ingress_password) || ENV["RAILS_INBOUND_EMAIL_PASSWORD"]
|
|
|
|
end
|
|
|
|
end
|
2018-10-06 22:02:08 -04:00
|
|
|
end
|