From 8be0d1334d5b75f48a2ee35cfe5ca06cbbef7db6 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 5 Sep 2019 02:38:59 +0500 Subject: [PATCH] Do not timeout if remembered --- app/models/user.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 2547d59..045fd49 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,4 +36,25 @@ class User < ApplicationRecord before_validation do self.account ||= Account.new end + + ########### + # Methods # + ########### + + def remember_exists_and_not_expired? + return false unless respond_to? :remember_created_at + return false unless respond_to? :remember_expired? + + remember_created_at && !remember_expired? + end + + def remember_expired? + remember_created_at.nil? || (remember_expires_at <= Time.now.utc) + end + + def timedout?(last_access) + return false if remember_exists_and_not_expired? + + !timeout_in.nil? && last_access && last_access <= timeout_in.ago + end end