mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Add #skip_confirmation_notification to Confirmable
This commit is contained in:
parent
22897150d8
commit
72cfaad618
2 changed files with 21 additions and 1 deletions
|
@ -34,7 +34,7 @@ module Devise
|
|||
|
||||
included do
|
||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||
after_create :send_on_create_confirmation_instructions, :if => :confirmation_required?
|
||||
after_create :send_on_create_confirmation_instructions, :if => :send_confirmation_notification?
|
||||
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
|
||||
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
|
||||
end
|
||||
|
@ -119,6 +119,12 @@ module Devise
|
|||
self.confirmed_at = Time.now.utc
|
||||
end
|
||||
|
||||
# Skips sending the confirmation notification email after_create. Unlike
|
||||
# #skip_confirmation!, record still requires confirmation.
|
||||
def skip_confirmation_notification!
|
||||
@skip_confirmation_notification = true
|
||||
end
|
||||
|
||||
# If you don't want reconfirmation to be sent, neither a code
|
||||
# to be generated, call skip_reconfirmation!
|
||||
def skip_reconfirmation!
|
||||
|
@ -223,6 +229,10 @@ module Devise
|
|||
self.class.reconfirmable && @reconfirmation_required
|
||||
end
|
||||
|
||||
def send_confirmation_notification?
|
||||
confirmation_required? && !@skip_confirmation_notification
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
||||
|
|
|
@ -104,6 +104,16 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
|
||||
user = new_user
|
||||
user.skip_confirmation_notification!
|
||||
|
||||
assert_email_not_sent do
|
||||
user.save!
|
||||
assert !user.confirmed?
|
||||
end
|
||||
end
|
||||
|
||||
test 'should find a user to send confirmation instructions' do
|
||||
user = create_user
|
||||
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
||||
|
|
Loading…
Reference in a new issue