Merge pull request #3350 from betagouv/secure_connexion_cleaner_date_comparison

Trusted_device: cleaner time comparison
This commit is contained in:
LeSim 2019-02-01 11:00:20 +01:00 committed by GitHub
commit 351f2872a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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