不活动/空闲后自动注销 [英] automatic logout after inactivity/idle
问题描述
如何在 rails 应用程序中设置,如果任何用户空闲 30 分钟或特定时间段,他应该自动注销.任何人都可以给出任何解决方案.我正在使用设备进行身份验证.任何帮助表示赞赏.
How to set up in the rails application that if any user is idle for 30 minutes or a specific period of time he should be automatically get logged out. Can any one give any solution . i am using devise for authentication purpose. Any help is appreciated .
推荐答案
你应该使用 超时
模型特征.
You should use Timeoutable
model trait.
Timeoutable 负责判断用户会话是否已经过期.当会话在配置的时间后到期时,将再次要求用户提供凭据,这意味着他/她将被重定向到登录页面.
Timeoutable takes care of veryfing whether a user session has already expired or not. When a session expires after the configured time, the user will be asked for credentials again, it means, he/she will be redirected to the sign in page.
Timeoutable 为 devise_for 添加以下选项:
Timeoutable adds the following options to devise_for:
- +timeout_in+:超时没有活动的用户会话的时间间隔.
在你的模型中你需要
devise :timeoutable
# along with :database_authenticatable, :registerable and other things.
另外,看看config/initializers/devise.rb
,你可以在那里配置超时值.
Also, take a look at config/initializers/devise.rb
, you can configure timeout value there.
这篇关于不活动/空闲后自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!