Save confirmation token to the database, if one does not exist but was requested, closes #377

This commit is contained in:
José Valim 2010-07-14 18:03:34 +02:00
parent 4f6113ab68
commit b4794e041b
2 changed files with 6 additions and 2 deletions

View File

@ -50,7 +50,7 @@ module Devise
# Send confirmation instructions by email
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
end
@ -127,6 +127,10 @@ module Devise
self.confirmation_sent_at = Time.now.utc
end
def generate_confirmation_token!
generate_confirmation_token && save(:validate => false)
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# confirmation instructions to it. If not user is found, returns a new user

View File

@ -133,7 +133,7 @@ class ConfirmableTest < ActiveSupport::TestCase
user.instance_eval { def confirmation_required?; false end }
user.save
user.send_confirmation_instructions
assert_not_nil user.confirmation_token
assert_not_nil user.reload.confirmation_token
end
test 'should not resend email instructions if the user change his email' do