Laravel Auth会话超时 [英] Laravel Auth session timeout

查看:129
本文介绍了Laravel Auth会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这方面已经看到了几个问题,到目前为止,所有答复似乎都集中于检测下一个User操作的到期时间. 无论是否能够执行此操作,我想要的是让服务器端代码检测到到期,然后强制刷新用户"屏幕.从概念上讲,该过程是这样的:

I have seen several questions in this area and so far all replies seem to focus on detecting expiration on the next User action. Regardless of being able to do this, what I want is to have the server side code detect the expiration and then force a refresh of the User screen. Conceptually, the process is something like this:

  1. 在服务器端检测到过期
  2. (可选)向用户发送一条消息,询问他们是否希望继续.如果没有响应,请强制注销过程并相应地建议用户.如果用户确认他们希望保留在会话中,则模拟一些活动以重置到期时间.如果未发送任何消息,只需强制一个新屏幕.

就我而言,我使用Auth登录并向用户授予管理权限.这包括访问维护表格/按钮.

In my case, I use Auth to login and grant administration rights to the user. This includes access to maintenance forms / buttons.

基本上我不想要的是一个屏幕,因为它已经过期,提示用户a)仍在登录,b)显示他们当时在做什么的详细信息.如果用户具有特殊权限,则它们在到期后不应保持可见状态.例如,管理员正在更改用户的个人详细信息并被叫走.鉴于他/她本应终止该过程并注销,所以如果他们未能这样做,则不应在屏幕上让其他人稍后看到这些详细信息.

Basically what I do NOT want is a screen left as it was pre-expiration suggesting that the User is a) still logged on and b) showing details of what they were doing at the time. If the User has special rights, they should not remain visible after expiration. For example, the administrator is changing a User's personal details and gets called away. Given that he/she should have terminated the process and logged out, if they failed to do this the details should not be left onscreen for some other person to see them sometime later.

理想的情况是某种形式的事件侦听器,但即使这样,我仍然不确定如何在不运行JS计时器循环的情况下强制进行屏幕更改.

The ideal would be some form of Event Listener but even then I am unsure as to how to force a screen change short of running a JS timer loop.

我想我不是唯一有这种要求的人,所以我的问题是...

I would assume that I am not the only one with this type of requirement so my question is ...

您如何在Laravel 5的约束下处理此类要求?

How do you handle this type of requirement within the constraints of Laravel 5?

推荐答案

会话的默认值在config/session.php下定义.您可以使用config helper函数config('session.lifetime')来获取值.

The default value of the session is defined under config/session.php. You can get the value by using the config helper function config('session.lifetime').

根据您的情况,您需要在客户端(javascript)上检查会话时间.

In your case you will need to check the session time on the client side (javascript.)

这里有一个代码示例,用于在会话到期之前刷新页面.该代码用于刀片模板.

Here a code example to refresh the page before the session expires. This code is for the blade template.

@if (Auth::check()) 
    <script>
    var timeout = ({{config('session.lifetime')}} * 60000) -10 ;
    setTimeout(function(){
        window.location.reload(1);
    },  timeout);



    </script>
@endif

您可以调整代码以提示对话框,以确认用户是否要延长会话时间,并执行ajax来获取或刷新会话时间.

You can adjust the code to prompt with a dialog to confirm if the user wants to extends his session time and do an ajax to get or refresh the session time.

这篇关于Laravel Auth会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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