角会话超时和管理 [英] Angular session timeout and management

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

问题描述

有没有办法使用Angularjs来管理用户会话?我的意思是:

Is there any way to manage user session using Angularjs?, I mean::


  • 会话超时 - 当系统处于闲置状态

  • 的通知时,会接近与选项恢复会话过期。

  • 重定向(或任何其他操作)试图提出一个要求,如果会话已过期时。

可能是拦截器的一个很好的选项来解决这个问题?你能提供一个例子吗?

Could be Interceptors one good option to solve this problem? Can you provide an example?

先谢谢了。

推荐答案

尝试 NG-闲置。这是简单的组件,您可以设置超时预警时间达到超时之前。然后你就可以查询用户注销或类似的服务器。

Try ng-idle. It's simple component where you can set the timeout and warning time before the timeout is reached. Then you can query server for user logout or something similar.

myApp.config(function(IdleProvider, KeepaliveProvider) {
  IdleProvider.idle(900); // 15 min
  IdleProvider.timeout(60);
  KeepaliveProvider.interval(600); // heartbeat every 10 min
  KeepaliveProvider.http('/api/heartbeat'); // URL that makes sure session is alive
});

myApp.run(function($rootScope, Idle) {
  Idle.watch();
  $rootScope.$on('IdleStart', function() { /* Display modal warning or sth */ });
  $rootScope.$on('IdleTimeout', function() { /* Logout user */ });
});

在上述结构中,当用户闲置900S(不移动鼠标,preSS任何键或按钮等),正在显示警告。然后,它会等待60秒,注销用户(发送请求到可能破坏服务器会话服务器)。

In the above configuration, when user is idle for 900s (does not move mouse, press any key or button etc), warning is being displayed. It will then wait 60s and log out user (send request to a server that possibly destroys server session).

为了确保服务器会话不会过期(即使一切用户正在做的是移动鼠标)的存活服务将请求发送到服务器每10分钟。这一次,有小于服务器会话过期时间。

In order to make sure server session does not expire (even if everything user is doing is moving mouse) the Keepalive service will send a request to the server every 10 minutes. This time has to less than server session expiration time.

结帐的演示

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

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