检测设备会话何时到期 [英] Detect when a devise session expires

查看:26
本文介绍了检测设备会话何时到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录用户会话何时超时,使用 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?

推荐答案

我没有看到任何类型的钩子,但是您可以覆盖设计使用的 timeoutable 模块中的代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆