diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index a6a23fc986..c2f67376ba 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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 diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 6ade6a2bce..3b4b17f0e6 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -34,8 +34,8 @@ def self.included(base) 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 @@ def send_confirmation_instructions # 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 @@ def unless_confirmed 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 diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index d687905f00..723d855e95 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -149,38 +149,23 @@ def setup 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