检测设备会话到期时 [英] Detect when a devise session expires
问题描述
我想记录用户的会话是否超时,使用devise和:timeoutable
。
I'd like to record when a user's session has timed out, using devise and :timeoutable
.
目前,:timeoutable
正在按预期工作,并在指定的不活动时间段后将用户重定向到登录页面,但除此之外,我们还要登录这有助于改善我们的超时时间。
At the moment, :timeoutable
is working as expected and redirecting users to the login page after the specified period of inactivity, but in addition to this we'd like to log when this happens to help refine our timeout period.
(显然,除非用户明确注销,否则所有会话都将超时。我们将检查自上次活动以来的时间,以确定是否这是一个自然的超时,或者更可能是我们设置太短的超时时间。)
(Obviously all sessions will time out unless the user explicitly logs out. We'll check the time since last activity to determine if it is a natural timeout or is more likely a result of us setting too short a timeout period.)
是否有一个事件,我可以挂钩或另一种检测方式会话超时在 SessionController
?
Is there an event that I can hook into or another way of detecting session timeout in the SessionController
?
推荐答案
我没有看到任何一种钩子,但你可以只是覆盖由devise使用的超时模块中的代码:
i've not seen any kind of hook, but you could just override the code in the timeoutable module that is used by devise:
module Devise
module Models
module Timeoutable
def timedout?(last_access)
# your custom code goes into this method
return false if remember_exists_and_not_expired?
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
end
end
end
end
这篇关于检测设备会话到期时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!