我有一个使用authlogic进行身份验证的rails应用程序。我有60分钟的超时设置。
当会话超时时,用户将被带回基本登录屏幕,但没有解释为什么他们已被注销。有没有办法在闪存中设置消息,以便可以向用户解释?我很惊讶这不是默认行为。
答案 0 :(得分:1)
我还没有测试过,但您可以尝试在应用程序控制器中重新定义enforce_timeout方法。像这样:
private
def enforce_timeout
if stale?
self.stale_record = record
self.record = nil
flash[:now] = "Session timed out"
end
end
end
如果它不起作用,你可能想玩它,这是我看过的来源:https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/session/timeout.rb
答案 1 :(得分:1)
只需编写自己的before_filter来检查登录用户,并使用AuthLogic :: Session模块的stale?
方法设置闪存。这就是我的样子:
def login_required
if current_user_session && current_user_session.stale?
flash[:error] = "Timeout message here"
end
redirect_to_login unless logged_in?
end