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

Allow the mailer class to be configured.

This commit is contained in:
José Valim 2010-06-12 20:56:55 +02:00
parent c4a4032b6b
commit a2f84852af
6 changed files with 20 additions and 3 deletions

View file

@ -6,6 +6,7 @@
* Added authenticate(scope) support in routes (by github.com/wildchild) * Added authenticate(scope) support in routes (by github.com/wildchild)
* Added after_update_path_for to registrations controller (by github.com/thedelchop) * Added after_update_path_for to registrations controller (by github.com/thedelchop)
* Added anybody_signed_in? helper (by github.com/SSDany) * Added anybody_signed_in? helper (by github.com/SSDany)
* Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
* bug fix * bug fix
* confirmation_required? is properly honored on active? calls. (by github.com/paulrosania) * confirmation_required? is properly honored on active? calls. (by github.com/paulrosania)

View file

@ -1,4 +1,5 @@
require 'active_support/core_ext/numeric/time' require 'active_support/core_ext/numeric/time'
require 'active_support/dependencies'
module Devise module Devise
autoload :FailureApp, 'devise/failure_app' autoload :FailureApp, 'devise/failure_app'
@ -161,6 +162,17 @@ module Devise
yield self yield self
end end
# Get the mailer class from the mailer reference object.
def self.mailer
@@mailer_ref.get
end
# Set the mailer reference object to access the mailer.
def self.mailer=(class_name)
@@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
end
self.mailer = "Devise::Mailer"
# Register a model in Devise. You can call this manually if you don't want # Register a model in Devise. You can call this manually if you don't want
# to use devise routes. Check devise_for in routes to know which options # to use devise routes. Check devise_for in routes to know which options
# are available. # are available.

View file

@ -51,7 +51,7 @@ module Devise
# Send confirmation instructions by email # Send confirmation instructions by email
def send_confirmation_instructions def send_confirmation_instructions
generate_confirmation_token if self.confirmation_token.nil? generate_confirmation_token if self.confirmation_token.nil?
::Devise::Mailer.confirmation_instructions(self).deliver ::Devise.mailer.confirmation_instructions(self).deliver
end end
# Resend confirmation token. This method does not need to generate a new token. # Resend confirmation token. This method does not need to generate a new token.

View file

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

View file

@ -28,7 +28,7 @@ module Devise
# Resets reset password token and send reset password instructions by email # Resets reset password token and send reset password instructions by email
def send_reset_password_instructions def send_reset_password_instructions
generate_reset_password_token! generate_reset_password_token!
::Devise::Mailer.reset_password_instructions(self).deliver ::Devise.mailer.reset_password_instructions(self).deliver
end end
protected protected

View file

@ -1,9 +1,13 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first # Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models. # four configuration values can also be set straight in your models.
Devise.setup do |config| Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com" config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# ==> ORM configuration # ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default), :mongoid # Load and configure the ORM. Supports :active_record (default), :mongoid
# (bson_ext recommended) and :data_mapper (experimental). # (bson_ext recommended) and :data_mapper (experimental).