1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge pull request #1228 from dasil003/master

Set up Recoverable to automatically confirm! if Comfirmable
This commit is contained in:
José Valim 2011-08-02 12:41:09 -07:00
commit 919404df53
6 changed files with 29 additions and 8 deletions

View file

@ -127,6 +127,11 @@ module Devise
generate_confirmation_token && save(:validate => false)
end
def after_password_reset
super
confirm! unless confirmed?
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

@ -29,7 +29,11 @@ module Devise
def reset_password!(new_password, new_password_confirmation)
self.password = new_password
self.password_confirmation = new_password_confirmation
clear_reset_password_token if valid?
if valid?
clear_reset_password_token
after_password_reset
end
save
end
@ -89,6 +93,9 @@ module Devise
self.reset_password_sent_at = nil if respond_to?(:reset_password_sent_at=)
end
def after_password_reset
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# password instructions to it. If not user is found, returns a new user

View file

@ -69,7 +69,7 @@ class ConfirmationTest < ActionController::IntegrationTest
assert_contain 'already confirmed'
end
test 'sign in user automatically after confirming it\'s email' do
test 'sign in user automatically after confirming its email' do
user = create_user(:confirm => false)
visit_user_confirmation_with_token(user.confirmation_token)

View file

@ -166,7 +166,7 @@ class PasswordTest < ActionController::IntegrationTest
assert user.reload.valid_password?('987654321')
end
test 'sign in user automatically after changing it\'s password' do
test 'sign in user automatically after changing its password' do
user = create_user
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
@ -174,8 +174,8 @@ class PasswordTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
end
test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
user = create_user(:confirm => false)
test 'does not sign in user automatically after changing its password if its locked' do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
@ -183,6 +183,15 @@ class PasswordTest < ActionController::IntegrationTest
assert !warden.authenticated?(:user)
end
test 'sign in user automatically and confirm after changing its password if its not confirmed' do
user = create_user(:confirm => false)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert warden.authenticated?(:user)
assert user.reload.confirmed?
end
test 'reset password request with valid E-Mail in XML format should return valid response' do
create_user
post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"}

View file

@ -121,7 +121,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_equal "not found", confirmation_user.errors[:email].join
end
test 'should send email instructions for the user confirm it\'s email' do
test 'should send email instructions for the user confirm its email' do
user = create_user
assert_email_sent do
User.send_confirmation_instructions(:email => user.email)
@ -219,7 +219,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert user.reload.active_for_authentication?
end
test 'should find a user to send email instructions for the user confirm it\'s email by authentication_keys' do
test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)

View file

@ -87,7 +87,7 @@ class ValidatableTest < ActiveSupport::TestCase
assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
end
test 'should not require password length when it\'s not changed' do
test 'should not require password length when its not changed' do
user = create_user.reload
user.password = user.password_confirmation = nil
assert user.valid?