Do not send confirmation e-mail when e-mail changes.
This commit is contained in:
parent
9d56aa9603
commit
8c1bab4951
|
@ -3,6 +3,7 @@
|
|||
|
||||
* deprecations
|
||||
* Renamed confirm_in to confirm_within
|
||||
* [#14] Do not send confirmation messages when user changes his e-mail
|
||||
|
||||
== 0.2.3
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ module Devise
|
|||
base.class_eval do
|
||||
extend ClassMethods
|
||||
|
||||
before_save :reset_confirmation, :if => :email_changed?
|
||||
after_save :send_confirmation_instructions, :if => :email_changed?
|
||||
before_create :generate_confirmation_token
|
||||
after_create :send_confirmation_instructions
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ module Devise
|
|||
# confirming it's account
|
||||
def reset_confirmation!
|
||||
unless_confirmed do
|
||||
reset_confirmation
|
||||
generate_confirmation_token
|
||||
save(false)
|
||||
send_confirmation_instructions
|
||||
end
|
||||
|
@ -115,26 +115,14 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
# Remove confirmation date from the user, ensuring after a user update
|
||||
# it's email, it won't be able to sign in without confirming it.
|
||||
def reset_confirmation
|
||||
generate_confirmation_token
|
||||
self.confirmed_at = nil
|
||||
end
|
||||
|
||||
# Generates a new random token for confirmation, and stores the time
|
||||
# this token is being generated
|
||||
def generate_confirmation_token
|
||||
self.confirmed_at = nil
|
||||
self.confirmation_token = friendly_token
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
end
|
||||
|
||||
# Resets the confirmation token with and save the record without
|
||||
# validating.
|
||||
def generate_confirmation_token!
|
||||
generate_confirmation_token && save(false)
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
# Attempt to find a user by it's email. If a record is found, send new
|
||||
|
|
|
@ -149,38 +149,23 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'should resend email instructions for the user reconfirming the email if it has changed' do
|
||||
test 'should not resend email instructions if the user change his email' do
|
||||
user = create_user
|
||||
user.email = 'new_test@example.com'
|
||||
assert_email_sent do
|
||||
user.save!
|
||||
end
|
||||
end
|
||||
|
||||
test 'should not resend email instructions if the user is updated but the email is not' do
|
||||
user = create_user
|
||||
user.confirmed_at = Time.now
|
||||
assert_email_not_sent do
|
||||
user.save!
|
||||
end
|
||||
end
|
||||
|
||||
test 'should reset confirmation status when updating email' do
|
||||
test 'should not reset confirmation status or token when updating email' do
|
||||
user = create_user
|
||||
assert_not user.confirmed?
|
||||
user.confirm!
|
||||
assert user.confirmed?
|
||||
user.email = 'new_test@example.com'
|
||||
user.save!
|
||||
assert_not user.reload.confirmed?
|
||||
end
|
||||
|
||||
test 'should reset confirmation token when updating email' do
|
||||
user = create_user
|
||||
token = user.confirmation_token
|
||||
user.email = 'new_test@example.com'
|
||||
user.save!
|
||||
assert_not_equal token, user.reload.confirmation_token
|
||||
user.reload
|
||||
assert user.confirmed?
|
||||
assert_nil user.confirmation_token
|
||||
end
|
||||
|
||||
test 'should not be able to send instructions if the user is already confirmed' do
|
||||
|
|
Loading…
Reference in New Issue