在用户通过超时注销之前向用户显示一条消息 [英] Show users a message before they are logged out by timeout

查看:130
本文介绍了在用户通过超时注销之前向用户显示一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Devise进行身份验证的Rails 4应用程序。我们要:

We have a Rails 4 app using Devise for authentication. We want to:


  • 在会话自动过期前1分钟向用户发送消息

  • 让用户点击此消息上的按钮继续他/她的会话

  • 如果他/她的会话过期,自动将用户发送到登录页面并显示消息

有没有任何Devise扩展或内置组件可以帮助我们做到这一点,还是需要滚动我们自己的解决方案?如果我们自己开始,有没有什么好的教程来完成这个或者我们可能会与之互动的Devise钩子的文档?

Are there any Devise extensions or build-in components that will help us do this, or will we need to roll our own solution? If we start on our own, are there any good tutorials for accomplishing this or documentation on the Devise hooks we'll likely be interacting with?

推荐答案

看起来,当我写这个答案的时候,没有任何宝石或者Devise的钩子来照顾我,所以我不得不推出自己的组件。

It looks like as of when I wrote this answer, there weren't any gems or Devise hooks to take care of this for me, so I had to roll out my own component.

撰写组件最困难的部分之一是找出如何向服务器发送请求,以检查用户在自动注销之前有多长时间。我不想发送该请求来重置自动注销定时器。这个问题解释了我如何处理这个任务: Devise - 请求不重设倒计时,直到用户由于不活动而退出

One of the most difficult parts of writing the component was figuring out how to send a request to the server to check how much longer the user had before being automatically logged out. I didn't want sending that request to reset the auto-log-out "timer." This question explains how I dealt with that task: Devise - Make a request without resetting the countdown until a user is logged out due to inactivity

这篇关于在用户通过超时注销之前向用户显示一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆