mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Merge pull request #2958 from karlentwistle/master
Find a resource based off its encrypted reset_password_token
This commit is contained in:
commit
d019e1ed1a
2 changed files with 19 additions and 0 deletions
|
@ -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)
|
||||
to_adapter.find_first(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
|
||||
|
|
Loading…
Add table
Reference in a new issue