mailers: fix procedure_after_confirmation in the confirmation email
As mailers are run asynchronously, they don't have access to the CurrentConfirmation defined in an earlier request. For the procedure_after_confirmation to be serialized to the Mailer, we need to pass it at creation time.
This commit is contained in:
parent
9ad56d8e9b
commit
8eb6dd78a1
2 changed files with 15 additions and 1 deletions
|
@ -15,7 +15,7 @@ class DeviseUserMailer < Devise::Mailer
|
||||||
|
|
||||||
def confirmation_instructions(record, token, opts = {})
|
def confirmation_instructions(record, token, opts = {})
|
||||||
opts[:from] = NO_REPLY_EMAIL
|
opts[:from] = NO_REPLY_EMAIL
|
||||||
@procedure = CurrentConfirmation.procedure_after_confirmation || nil
|
@procedure = opts[:procedure_after_confirmation] || nil
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,20 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
before_validation -> { sanitize_email(:email) }
|
before_validation -> { sanitize_email(:email) }
|
||||||
|
|
||||||
|
# Override of Devise::Models::Confirmable#send_confirmation_instructions
|
||||||
|
def send_confirmation_instructions
|
||||||
|
unless @raw_confirmation_token
|
||||||
|
generate_confirmation_token!
|
||||||
|
end
|
||||||
|
|
||||||
|
opts = pending_reconfirmation? ? { to: unconfirmed_email } : {}
|
||||||
|
|
||||||
|
# Make our procedure_after_confirmation available to the Mailer
|
||||||
|
opts[:procedure_after_confirmation] = CurrentConfirmation.procedure_after_confirmation
|
||||||
|
|
||||||
|
send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
|
||||||
|
end
|
||||||
|
|
||||||
# Callback provided by Devise
|
# Callback provided by Devise
|
||||||
def after_confirmation
|
def after_confirmation
|
||||||
link_invites!
|
link_invites!
|
||||||
|
|
Loading…
Reference in a new issue