mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Find a resource based off its encrypted reset_password_token
This commit is contained in:
parent
145ce9e1de
commit
de57ef83fb
2 changed files with 19 additions and 0 deletions
|
@ -91,6 +91,13 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
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
|
# 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
|
# password instructions to it. If user is not found, returns a new user
|
||||||
# with an email not found error.
|
# with an email not found error.
|
||||||
|
|
|
@ -181,4 +181,16 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
:reset_password_token
|
:reset_password_token
|
||||||
]
|
]
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue