Permalink
Browse files

Do not send confirmation e-mail when e-mail changes.

  • Loading branch information...
1 parent 9d56aa9 commit 8c1bab4951eaabc11d942a334b9ac620e54a53a8 @josevalim josevalim committed Oct 30, 2009
Showing with 10 additions and 36 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +4 −16 lib/devise/models/confirmable.rb
  3. +5 −20 test/models/confirmable_test.rb
View
1 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
View
20 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
View
25 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

0 comments on commit 8c1bab4

Please sign in to comment.