Ruby on Rails 和 Restful_authentication 插件

发布于 2024-07-22 21:21:19 字数 128 浏览 4 评论 0原文

我在登录页面使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷弦 2024-07-29 21:21:19

您可以在 Rails 2.3 中的 config/intializers/session_store.rb 文件中配置会话过期时间。

只需添加以下选项:

:expire_after => 60.minutes

或者,您可以通过在 before_filter 中使用以下内容来更改每个控制器/操作的过期时间:

request.session_options = request.session_options.dup
request.session_options[:expire_after] = 5.minutes
request.session_options.freeze

这些说明位于: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:

:expire_after => 60.minutes

Alternatively, you can change expiration times per controller/action by using the following in a before_filter:

request.session_options = request.session_options.dup
request.session_options[:expire_after] = 5.minutes
request.session_options.freeze

These instructions were found at: http://squarewheel.pl/posts/3, which also has a link to a plugin for rails < 2.3.

久隐师 2024-07-29 21:21:19

请注意,这仅设置 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

舞袖。长 2024-07-29 21:21:19

在您的 application.rb 中:

  before_filter :update_activity_time, :except => [:login, :logout]

   def update_activity_time
     session[:expires_at] = 60.minutes.from_now #default 60
   end

in your application.rb:

  before_filter :update_activity_time, :except => [:login, :logout]

   def update_activity_time
     session[:expires_at] = 60.minutes.from_now #default 60
   end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文