1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Provide a send_devise_notification hook

This commit is contained in:
José Valim 2012-06-16 13:00:51 +02:00
parent 85c90671bc
commit 18a18e4c72
4 changed files with 41 additions and 4 deletions

View file

@ -134,6 +134,43 @@ module Devise
RUBY
end
protected
# This is an internal method called every time Devise needs
# to send a notification/mail. This can be overriden if you
# need to customize the e-mail delivery logic. For instance,
# if you are using a queue to deliver e-mails (delayed job,
# sidekiq, resque, etc), you must add the delivery to the queue
# just after the transaction was committed. To achieve this,
# you can override send_devise_notification to store the
# deliveries until the after_commit callback is triggered:
#
# class User
# devise :database_authenticatable, :confirmable
#
# after_commit :send_pending_notifications
#
# protected
#
# def send_devise_notification(notification)
# pending_notifications << notification
# end
#
# def send_pending_notifications
# pending_notifications.each do |n|
# devise_mailer.send(n, self).deliver
# end
# end
#
# def pending_notifications
# @pending_notifications ||= []
# end
# end
#
def send_devise_notification(notification)
devise_mailer.send(notification, self).deliver
end
module ClassMethods
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
:case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)

View file

@ -78,7 +78,7 @@ module Devise
@reconfirmation_required = false
generate_confirmation_token! if self.confirmation_token.blank?
self.devise_mailer.confirmation_instructions(self).deliver
send_devise_notification(:confirmation_instructions)
end
# Resend confirmation token. This method does not need to generate a new token.
@ -125,7 +125,7 @@ module Devise
# instructions on creation. This can be overriden
# in models to map to a nice sign up e-mail.
def send_on_create_confirmation_instructions
self.devise_mailer.confirmation_instructions(self).deliver
send_devise_notification(:confirmation_instructions)
end
# Callback to overwrite if confirmation is required or not.

View file

@ -60,7 +60,7 @@ module Devise
# Send unlock instructions by email
def send_unlock_instructions
self.devise_mailer.unlock_instructions(self).deliver
send_devise_notification(:unlock_instructions)
end
# Resend the unlock instructions if the user is locked.

View file

@ -45,7 +45,7 @@ module Devise
# Resets reset password token and send reset password instructions by email
def send_reset_password_instructions
generate_reset_password_token! if should_generate_reset_token?
self.devise_mailer.reset_password_instructions(self).deliver
send_devise_notification(:reset_password_instructions)
end
# Checks if the reset password token sent is within the limit time.