mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Reworking the internals of Devise::Mailer - mainly so headers can be tweaked without overwriting/rewriting #setup_mail. (I'm using a custom mailer which is a subclass of Devise::Mailer, and want to change headers/templates in some situations - but perhaps this is useful generally).
This commit is contained in:
parent
0388380614
commit
29e9be92b0
1 changed files with 27 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
class Devise::Mailer < ::ActionMailer::Base
|
||||
include Devise::Controllers::ScopedViews
|
||||
attr_reader :devise_mapping, :resource
|
||||
attr_reader :scope_name, :resource
|
||||
|
||||
def confirmation_instructions(record)
|
||||
setup_mail(record, :confirmation_instructions)
|
||||
|
@ -13,24 +13,38 @@ class Devise::Mailer < ::ActionMailer::Base
|
|||
def unlock_instructions(record)
|
||||
setup_mail(record, :unlock_instructions)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
# Configure default email options
|
||||
def setup_mail(record, action)
|
||||
@scope_name = Devise::Mapping.find_scope!(record)
|
||||
@devise_mapping = Devise.mappings[@scope_name]
|
||||
@resource = instance_variable_set("@#{@devise_mapping.name}", record)
|
||||
|
||||
initialize_from_record record
|
||||
|
||||
mail headers_for(action)
|
||||
end
|
||||
|
||||
def initialize_from_record(record)
|
||||
@scope_name = Devise::Mapping.find_scope!(record)
|
||||
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
||||
end
|
||||
|
||||
def devise_mapping
|
||||
@devise_mapping ||= Devise.mappings[scope_name]
|
||||
end
|
||||
|
||||
def headers_for(action)
|
||||
headers = {
|
||||
:subject => translate(@devise_mapping, action),
|
||||
:from => mailer_sender(@devise_mapping),
|
||||
:to => record.email,
|
||||
:subject => translate(devise_mapping, action),
|
||||
:from => mailer_sender(devise_mapping),
|
||||
:to => resource.email,
|
||||
:template_path => template_paths
|
||||
}
|
||||
|
||||
headers.merge!(record.headers_for(action)) if record.respond_to?(:headers_for)
|
||||
mail(headers)
|
||||
|
||||
if resource.respond_to?(:headers_for)
|
||||
headers.merge!(resource.headers_for(action))
|
||||
end
|
||||
|
||||
headers
|
||||
end
|
||||
|
||||
def mailer_sender(mapping)
|
||||
|
|
Loading…
Reference in a new issue