开发者

How do I set a message in the flash when authlogic times out a user?

I have a rails app which uses authlogic for authentication. I have a 60 minute timeout set.

When a session times out the user is taken back to a basic login screen but there is no explanation given for why they have been logged out. Is there a way of setting a message in the flash so that this can be explained to the use开发者_如何学JAVAr? I'm surprised this isn't default behaviour.


Just write your own before_filter to check for a logged in user, and set the flash there, using the stale? method of the AuthLogic::Session module. This is how mine looks like:

def login_required
  if current_user_session && current_user_session.stale?
    flash[:error] = "Timeout message here" 
  end
  redirect_to_login unless logged_in?
end


I haven't tested it, but you could try to redefine the enforce_timeout method in application controller. Something like this:

private

def enforce_timeout
      if stale?
        self.stale_record = record
        self.record = nil
        flash[:now] = "Session timed out"
    end
  end
end

You may want to play around with it if it doesn't work, here's the source I looked at: https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/session/timeout.rb

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜