mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:08:05 -05:00
Find a resource based off its encrypted reset_password_token
This commit is contained in:
@@ -91,6 +91,13 @@ module Devise
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by password reset token. If a user is found, return it
|
||||
# If a user is not found, return nil
|
||||
def with_reset_password_token(token)
|
||||
reset_password_token = Devise.token_generator.digest(self, :reset_password_token, token)
|
||||
find_by_reset_password_token(reset_password_token)
|
||||
end
|
||||
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# password instructions to it. If user is not found, returns a new user
|
||||
# with an email not found error.
|
||||
|
||||
@@ -181,4 +181,16 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
:reset_password_token
|
||||
]
|
||||
end
|
||||
|
||||
test 'should return a user based on the raw token' do
|
||||
user = create_user
|
||||
raw = user.send_reset_password_instructions
|
||||
|
||||
assert_equal User.with_reset_password_token(raw), user
|
||||
end
|
||||
|
||||
test 'should return nil if a user based on the raw token is not found' do
|
||||
assert_equal User.with_reset_password_token('random-token'), nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user