Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Be backwards compatible with old cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasparila committed Jun 13, 2016
1 parent b34a55f commit cb14ff8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/devise-authy/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ def remember_device

def require_token?
id = warden.session(resource_name)[:id]
cookie = JSON.parse(cookies.signed[:remember_device])
if cookie.present? &&
(Time.now.to_i - cookie['expires'].to_i) < \
resource_class.authy_remember_device.to_i &&
cookie['id'] == id
return false
cookie = cookies.signed[:remember_device]

# backwords compatibility for old cookies which just have expiration
# time and no id
if cookie.to_s =~ %r{\A\d+\Z}
return (Time.now.to_i - cookie.to_i) > \
resource_class.authy_remember_device.to_i
end

return true
cookie = JSON.parse(cookie)
return cookie.blank? || (Time.now.to_i - cookie['expires'].to_i) > \
resource_class.authy_remember_device.to_i || cookie['id'] != id
end

def is_devise_sessions_controller?
Expand Down

0 comments on commit cb14ff8

Please sign in to comment.