Skip to content

Commit cc21e4c

Browse files
committed
Do not set unlock_token attribute to undigested value after unlocking user with token
1 parent c8a64b5 commit cc21e4c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/devise/models/lockable.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,10 @@ def send_unlock_instructions(attributes = {})
187187
# If the user is not locked, creates an error for the user
188188
# Options must have the unlock_token
189189
def unlock_access_by_token(unlock_token)
190-
original_token = unlock_token
191-
unlock_token = Devise.token_generator.digest(self, :unlock_token, unlock_token)
190+
unlock_token = Devise.token_generator.digest(self, :unlock_token, unlock_token)
192191

193192
lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
194193
lockable.unlock_access! if lockable.persisted?
195-
lockable.unlock_token = original_token
196194
lockable
197195
end
198196

test/models/lockable_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ def setup
201201
raw = user.send_unlock_instructions
202202
locked_user = User.unlock_access_by_token(raw)
203203
assert_equal user, locked_user
204+
assert_not locked_user.changed?
204205
assert_not user.reload.access_locked?
206+
assert_nil user.reload.unlock_token
205207
end
206208

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

0 commit comments

Comments
 (0)