Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/devise/models/lockable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,10 @@ def send_unlock_instructions(attributes = {})
# If the user is not locked, creates an error for the user
# Options must have the unlock_token
def unlock_access_by_token(unlock_token)
original_token = unlock_token
unlock_token = Devise.token_generator.digest(self, :unlock_token, unlock_token)
unlock_token = Devise.token_generator.digest(self, :unlock_token, unlock_token)

lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
lockable.unlock_access! if lockable.persisted?
lockable.unlock_token = original_token
lockable
end

Expand Down
2 changes: 2 additions & 0 deletions test/models/lockable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def setup
raw = user.send_unlock_instructions
locked_user = User.unlock_access_by_token(raw)
assert_equal user, locked_user
assert_not locked_user.changed?
assert_not user.reload.access_locked?
assert_nil user.reload.unlock_token
end

test 'should return a new record with errors when a invalid token is given' do
Expand Down