Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1228 from dasil003/master

Set up Recoverable to automatically confirm! if Comfirmable
  • Loading branch information...
commit 919404df53a0ee9a8c5be50a3d74acf10ac2e38c 2 parents 560961e + fd07c74
@josevalim josevalim authored
View
5 lib/devise/models/confirmable.rb
@@ -127,6 +127,11 @@ def generate_confirmation_token!
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
9 lib/devise/models/recoverable.rb
@@ -29,7 +29,11 @@ module Recoverable
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 @@ def clear_reset_password_token
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
2  test/integration/confirmable_test.rb
@@ -69,7 +69,7 @@ def visit_user_confirmation_with_token(confirmation_token)
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
15 test/integration/recoverable_test.rb
@@ -166,7 +166,7 @@ def reset_password(options={}, &block)
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 @@ def reset_password(options={}, &block)
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 @@ def reset_password(options={}, &block)
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
4 test/models/confirmable_test.rb
@@ -121,7 +121,7 @@ def setup
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 @@ def setup
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
2  test/models/validatable_test.rb
@@ -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?
Please sign in to comment.
Something went wrong with that request. Please try again.