Ruby on Rails 和 Restful_authentication 插件
我在登录页面使用restful_authentication 插件。 问题是,当我以用户身份登录后,我永远不会注销,直到我单击注销。 如何将会话超时设置为 15 分钟? 例如,15 分钟后,如果我访问任何页面,我应该被重定向到登录页面。
I'm using the restful_authentication plugin for my login page. The problem is that after I log in as a user, I never get logged out until I click on log out. How do I set a session timeout of 15 minutes? For example, after 15 minutes if I go to any page, I should be redirected to the login page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 Rails 2.3 中的 config/intializers/session_store.rb 文件中配置会话过期时间。
只需添加以下选项:
或者,您可以通过在 before_filter 中使用以下内容来更改每个控制器/操作的过期时间:
这些说明位于:http://squarewheel.pl/posts/3,其中还有一个 Rails 插件的链接< 2.3.
You can configure session expiration times in the config/intializers/session_store.rb file in rails 2.3.
Just add the following option:
Alternatively, you can change expiration times per controller/action by using the following in a before_filter:
These instructions were found at: http://squarewheel.pl/posts/3, which also has a link to a plugin for rails < 2.3.
请注意,这仅设置 cookie 过期时间,而不设置服务器检查的会话过期时间(至少对于我为 Rails <2.3 编写的插件)。 要实现后者,您必须实现自己的 before_filter 来检查会话中的时间戳,并在时间高于可接受的限制时将其丢弃。 再说一遍,我还没有检查 >=2.3 是否需要这个
Note that this only sets cookie expiration time, not server-checked session expiration time (at least with the plugin I wrote for rails <2.3). To achieve the latter you'd have to implement your own before_filter that checks a timestamp in the session and discards it if the time is above the acceptable limit. Again, I haven't checked if this is needed for >=2.3
在您的 application.rb 中:
in your application.rb: