From 41ae1f46f4f3dd97af411fcb08f07ff0b22589eb Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 1 Feb 2019 10:54:20 +0100 Subject: [PATCH] Trusted_device: cleaner time comparison --- app/models/concerns/trusted_device_concern.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/trusted_device_concern.rb b/app/models/concerns/trusted_device_concern.rb index 5aff22882..9928adfa1 100644 --- a/app/models/concerns/trusted_device_concern.rb +++ b/app/models/concerns/trusted_device_concern.rb @@ -14,11 +14,15 @@ module TrustedDeviceConcern def trusted_device? trusted_device_cookie.present? && - Time.zone.now - TRUSTED_DEVICE_PERIOD < JSON.parse(trusted_device_cookie)['created_at'] + (Time.zone.now - TRUSTED_DEVICE_PERIOD) < trusted_device_cookie_created_at end private + def trusted_device_cookie_created_at + Time.zone.parse(JSON.parse(trusted_device_cookie)['created_at']) + end + def trusted_device_cookie cookies.encrypted[TRUSTED_DEVICE_COOKIE_NAME] end