Ruby on rails - Authlogic : periodically check if user session is valid

耗尽温柔 提交于 2019-12-01 05:27:49

From the AuthLogic source itself:

# For example, what if you had a javascript function that polled the server
# updating how much time is left in their session before it times out. Obviously
# you would want to ignore this request, because then the user would never
# time out. So you can do something like this in your controller:

def last_request_update_allowed?
 action_name != "update_session_time_left"
end

In your case, you would want to add the method to your controller using the name of your action:

def last_request_update_allowed?
  action_name != "check_session_timed_out"
end

Authlogic can do this for you. Just use in your models:

On User model:

acts_as_authentic do |c|
  c.logged_in_timeout(5.minutes)
end

... and on UserSession model:

self.logout_on_timeout = true

And simply work! =D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!