1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailbox/app/controllers/action_mailbox/base_controller.rb

37 lines
990 B
Ruby
Raw Normal View History

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