By default, just require e-mail on recover and lockable.

This commit is contained in:
José Valim 2010-12-28 23:00:23 +01:00
parent af1295284c
commit 8f20b13f84
5 changed files with 12 additions and 22 deletions

View File

@ -43,7 +43,7 @@
* bugfix * bugfix
* after_sign_in_path_for always receives a resource * after_sign_in_path_for always receives a resource
* Do not execute Warden::Callbacks on Devise::TestHelpers (by github.com/sgronblo) * Do not execute Warden::Callbacks on Devise::TestHelpers (by github.com/sgronblo)
* Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov) * Allow password recovery and account unlocking to change used keys (by github.com/RStankov)
* FailureApp now properly handles nil request.format * FailureApp now properly handles nil request.format
* Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7 * Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7
* Ensure namespaces has proper scoped views * Ensure namespaces has proper scoped views

View File

@ -132,7 +132,7 @@ module Devise
# with an email not found error. # with an email not found error.
# Options must contain the user email # Options must contain the user email
def send_unlock_instructions(attributes={}) def send_unlock_instructions(attributes={})
lockable = find_or_initialize_with_errors(authentication_keys, attributes, :not_found) lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted? lockable.resend_unlock_token if lockable.persisted?
lockable lockable
end end
@ -161,6 +161,10 @@ module Devise
Devise.friendly_token Devise.friendly_token
end end
def unlock_keys
[:email]
end
Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in) Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in)
end end
end end

View File

@ -57,7 +57,7 @@ module Devise
# with an email not found error. # with an email not found error.
# Attributes must contain the user email # Attributes must contain the user email
def send_reset_password_instructions(attributes={}) def send_reset_password_instructions(attributes={})
recoverable = find_or_initialize_with_errors(authentication_keys, attributes, :not_found) recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
recoverable.send_reset_password_instructions if recoverable.persisted? recoverable.send_reset_password_instructions if recoverable.persisted?
recoverable recoverable
end end
@ -67,6 +67,10 @@ module Devise
generate_token(:reset_password_token) generate_token(:reset_password_token)
end end
def reset_password_keys
[:email]
end
# Attempt to find a user by it's reset_password_token to reset it's # Attempt to find a user by it's reset_password_token to reset it's
# password. If a user is found, reset it's password and automatically # password. If a user is found, reset it's password and automatically
# try saving the record. If not user is found, returns a new user # try saving the record. If not user is found, returns a new user

View File

@ -186,15 +186,6 @@ class LockableTest < ActiveSupport::TestCase
end end
end end
test 'should require all authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
unlock_user = User.send_unlock_instructions(:email => user.email)
assert_not unlock_user.persisted?
assert_equal "can't be blank", unlock_user.errors[:username].join
end
end
test 'should not be able to send instructions if the user is not locked' do test 'should not be able to send instructions if the user is not locked' do
user = create_user user = create_user
assert_not user.resend_unlock_token assert_not user.resend_unlock_token

View File

@ -85,7 +85,7 @@ class RecoverableTest < ActiveSupport::TestCase
assert_not reset_password_user.persisted? assert_not reset_password_user.persisted?
assert_equal "not found", reset_password_user.errors[:email].join assert_equal "not found", reset_password_user.errors[:email].join
end end
test 'should find a user to send instructions by authentication_keys' do test 'should find a user to send instructions by authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do swap Devise, :authentication_keys => [:username, :email] do
user = create_user user = create_user
@ -93,15 +93,6 @@ class RecoverableTest < ActiveSupport::TestCase
assert_equal reset_password_user, user assert_equal reset_password_user, user
end end
end end
test 'should require all authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
reset_password_user = User.send_reset_password_instructions(:email => user.email)
assert_not reset_password_user.persisted?
assert_equal "can't be blank", reset_password_user.errors[:username].join
end
end
test 'should reset reset_password_token before send the reset instructions email' do test 'should reset reset_password_token before send the reset instructions email' do
user = create_user user = create_user