问题描述
在 AngularJS 1.* 中,有两个非常有用的提供程序: $ idleProvider
和 $ keepaliveProvider
.我使用它们来处理会话超时,并自动注销先前项目中的用户.我们现在正在与 Angular2 从团队开始一个新项目,我想知道是否有计划为这些项目提供类似的支持吗?理想情况下,我们可以拥有一种自动从客户端注销用户的机制.这是我们在 AngularJS 中如何完成此操作的源代码片段–如何使用 Angular2 完成此操作?
In AngularJS 1.* there are two providers that arevery useful, $idleProvider
and $keepaliveProvider
. I used these to handle session timeouts and automatically logout user's in previous project's. We are starting a new project now from the group up with Angular2 and I want to know if there is a plan for having similar support to these? Ideally we could have a mechanism that automatically logs out the user from the client. Here is the snippet of the source from how we accomplished this in AngularJS -- how can this be done with Angular2?
// Configure Idle Session Timeout
userModule.config([
'KeepaliveProvider', 'IdleProvider',
($keepaliveProvider, $idleProvider) => {
var str = $('#IdleSessionTimeout').text();
var idleTimeOut = parseInt(str);
var interval = 60;
if (isNaN(idleTimeOut)) {
idleTimeOut = 20;
interval = 10;
} else {
idleTimeOut *= 60; // Convert minutes -> seconds
}
$idleProvider.idle(idleTimeOut);
// If we ever want to warn user they are about to timeout
//$idleProvider.timeout(5);
$keepaliveProvider.interval(interval);
}
]);
userModule.run(($rootScope) => {
$rootScope.$on('IdleTimeout', () => {
// On timeout, end the user session by redirecting to logout
var url = window.location.href;
url = url.replace(/\/\#.*$/, "/Account/Logout");
window.location.href = url;
});
});
// Activate Timeout Monitoring
userModule.run(['Idle', ($idle) => {
$idle.watch();
}]);
请帮助...
推荐答案
对于我来说,这实际上是对 AngularJS $ idleProvider
和 $ keepaliveProvider的误解
实际上不是 Angular 小组的成员.这是由"Hacked By Chinese"创建的,他已经编写(并维护了)针对 Angular2 的两个端口:
This was actually a misconception on my part as the AngularJS $idleProvider
and $keepaliveProvider
are not actually by the Angular team. This is was created by "Hacked By Chinese" and he has written (and maintained) the two ports targeting Angular2:
- 先前称为
$ idleProvider
:这篇关于Angular2中的AngularJS $ idleProvider和$ keepaliveProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!