本文介绍了在闲置/闲置后自动退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在rails应用程序中设置,如果任何用户空闲30分钟或特定时间段,他应该自动注销。
任何人都可以提供任何解决方案。我正在使用devise进行身份验证。任何帮助都不胜感激。

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将以下选项添加到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.

这篇关于在闲置/闲置后自动退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:03
查看更多