标签: ng-idle

使用基于空闲用户的Angularjs自动注销

是否可以确定用户是否处于非活动状态,并在使用angularjs说不活动10分钟后自动将其注销?

我试图避免使用jQuery,但我找不到有关如何在angularjs中执行此操作的任何教程或文章.任何帮助,将不胜感激.

angularjs ng-idle

77
推荐指数
5
解决办法
9万
查看次数

如果在浏览器中打开了多个选项卡/窗口,则为ng-idle问题

我有一个要求,如果它闲置一段时间我必须注销用户.我正在使用ng-idle 0.3.2.

如果在浏览器中打开了多个选项卡/窗口,我会遇到问题.如果我正在使用选项卡,并且在我正在处理的活动选项卡上时未登录的选项卡仍然登录,因为它处于活动状态.

如何在我处理其他类似标签时阻止从非活动标签退出?

angularjs ng-idle

6
推荐指数
2
解决办法
6218
查看次数

AngularJS注入第三方模块ngIdle

我有一个控制器,如下所示.

(function () {
"use strict";
var app = angular.module('Demo')
    .controller('MainController', ['$rootScope', '$scope', '$location', 'curUser',MainController]);


 function MainController($rootScope, $scope,  $location, curUser) {
       //some logic here  
 }());
Run Code Online (Sandbox Code Playgroud)

我试图包含一个名为ngIdle的第三方模块,结果代码如下所示.

(function () {
"use strict";
var app = angular.module('Demo', ['ngIdle'])
    .controller('MainController', ['$rootScope', '$scope', '$location', 'curUser','Idle', function ($rootScope, $scope, $location, curUser, Idle) {


    }]).config(function (IdleProvider, KeepaliveProvider) {
        // configure Idle settings
        IdleProvider.idle(5); // in seconds
        IdleProvider.timeout(5); // in seconds
        KeepaliveProvider.interval(2); // in seconds
    })
    .run(function (Idle) {
        // start watching when the app runs. also …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-factory ng-idle

6
推荐指数
1
解决办法
137
查看次数

AngularJS:未知提供者:$ idleProvider

很多其他有类似问题的人,但决议似乎不适用于我的具体问题.

我正在尝试使用ngIdle(https://github.com/HackedByChinese/ng-idle)库但似乎无法在没有出现此错误的情况下运行它 - 未捕获错误:[$ injector:modulerr]无法实例化模块myAuditModule由于:错误:[$ injector:unpr]未知提供者:$ idleProvider

这是我的模块代码,

(function () {
    app = angular.module("myAuditModule", ['ui.bootstrap', 'ngRoute', 'ngCookies', 'ngDragDrop', 'ngIdle']);

    // configure the routes
    app.config(function ($routeProvider, $idleProvider, $keepaliveProvider) {

        $idleProvider.idleDuration(10 * 60); // 10 minutes idle
        $idleProvider.warningDuration(30); // 30 second warning
        $keepaliveProvider.interval(5 * 60); // 5 minute keep-alive ping

        $routeProvider

             //route for the logging in page
            .when('/', {
                templateUrl: 'Views/Login.html',
                controller: 'loginController'
            })

    });

    })();
Run Code Online (Sandbox Code Playgroud)

该文件包含在我的项目中,并且在网站运行时显示在开发者控制台中 -

   <script src="/Scripts/angular-idle.js"></script>
Run Code Online (Sandbox Code Playgroud)

唯一的依赖是你需要使用1.2或更高的角度,我就是这样.

有任何想法吗?

angularjs ng-idle

4
推荐指数
1
解决办法
6254
查看次数

NgIdle -Angular- 如何仅在单击对话框时停止倒计时值

我在我的 angular 应用程序中实现了一个会话超时模块,它监视空闲时间并打开会话超时对话框并在对话框上显示倒计时值。问题是当我在该屏幕上移动鼠标或至少在触摸该屏幕时倒计时值停止,但我想仅当我单击对话框上的任何内容而不是屏幕时停止对话框上的倒计时值。我认为如果我们提供自定义中断,如下面的链接所示,就可以做到这一点

例如,如果我仅配置为鼠标单击,它可以停止对话框上的倒计时,但这不会发生。可能这个问题可能是因为我正在从另一个组件打开会话超时对话框。

但我无法停止倒计时,这是我的示例代码

this.idle.onIdleStart.subscribe(() => {
  console.log('on idle start');
  let dialogRef;

  if (this.dialogRef === undefined || this.dialogRef === null) {

    dialogRef = this.dialog['open'](SessionTimeoutDialogComponent, {
      width: '30%',
      data: {idleTime: 10, timeoutTime: 10},
      panelClass: 'session-timeout-dialog'
    });
    this.dialogRef = dialogRef;
  }

  this.dialogRef.afterClosed().subscribe(result => {
    this.timeoutTime = result;
  });
  this.dialogRef = dialogRef;
});


 this.idle.onTimeoutWarning.subscribe((countdown) => {
  this.timeoutTime = countdown;
  this.dataService.changeVersionSelectionData(countdown);

});
Run Code Online (Sandbox Code Playgroud)

谁能指导我们如何做到这一点?

ng-idle angular

4
推荐指数
1
解决办法
2253
查看次数

如何在每次成功登录时防止 ng2-idle 实例化多次

我有一个问题,我将空闲设置为在会话到期前一分钟显示弹出窗口。然后会话超时或用户注销。下次用户登录时,他们现在有 2 个超时时弹出窗口。用户注销并再次登录,现在有 3 个弹出窗口,依此类推。用户注销时如何销毁当前的 Idle 实例?

我的设置如下:

constructor(private idle: Idle, ...) {}

ngOnInit() {
    this.setIdle();
}

private setIdle() {
    // Client activity timeout. 29 minutes to 'idle', 1 minute beyond that to timeout
    this.ngZone.runOutsideAngular(() => {
        // this.idle.setIdle(29 * 60);
        // this.idle.setTimeout(1 * 60);
        this.idle.setIdle(10);
        this.idle.setTimeout(10);
        this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
    });


    this.idle.onTimeout.subscribe(() => {
        this.ngZone.run(() => {
            this.errorDialogRef.close();
            sessionStorage.setItem('sessionExpired', 'true');
            this.displayErrorModal(true);
        });

    });

    this.idle.onIdleStart.subscribe(() => {
        this.ngZone.run(() => {
            this.displayIdleWarning();
        });
    });

    this.ngZone.runOutsideAngular(() => {
        this.idle.watch();
    });
}
Run Code Online (Sandbox Code Playgroud)

在注销过程中,我尝试了this.idle.stop()delete …

ng-idle angular

3
推荐指数
1
解决办法
2912
查看次数

ng-idle/core onIdleEnd 和 Mat-Dialog 有问题

我在 Ng-Idle、Material 6 和 Angular 6 中发现了一个问题

"@ng-idle/core": "^6.0.0-beta.3"
"@ng-idle/keepalive": "^6.0.0-beta.3"
"@angular/core": "^6.1.9"
"@angular/cdk": "^6.4.7"
"@angular/material": "^6.4.7"
Run Code Online (Sandbox Code Playgroud)

场景

当用户空闲时,对话框(弹出窗口)会显示用户退出系统之前的倒计时。如果用户在用鼠标活动注销之前返回,倒计时将停止并且对话框将关闭/消失。

问题

但是,在 Angular 5 中,此功能一直运行良好,直到我升级到 Angular 6。当用户在 之前返回时onTimeout,它会触发 ,onIdleEnd但对话框不会在鼠标活动时消失。我创建了一个 Angular 6 应用程序来复制这个问题。我试图确定这是 Ng-Idle 还是 Angular 问题。

使用 Ng-Idle 进行 Stackblitz

Stackblitz 显示 Mat-Dialog 在 10 秒倒计时后关闭

GitHub

有没有人遇到过这个问题?

ng-idle angular-material2 angular

3
推荐指数
1
解决办法
2041
查看次数

Angular 6 ng-空闲

我有一个运行良好的 Angular 项目,我正在实施 NG-IDLE 和 KeepAlive,以保持会话新鲜并在 API 会话到期之前注销用户。

我的问题是 ng-idle 也在登录页面上运行,这显然不是必需的,因为当它超时时,它会将人带到登录页面。

因此,我在 app.component.ts 中启动并运行了 ng-idle 和 KeepAlive,但由于我使用的是延迟加载,因此我还有一个 authentication.module.ts 和一个 login.component.ts。

我的根 app.component.ts 中的代码如下:

import { Component } from '@angular/core';

import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';
import { Keepalive } from '@ng-idle/keepalive';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {

    idleState = 'Not started.';
    timedOut = false;
    lastPing?: Date = null;

    constructor(private idle: Idle, private keepalive: Keepalive) {

        // sets an idle timeout of 5 seconds, …
Run Code Online (Sandbox Code Playgroud)

keep-alive ng-idle angular

3
推荐指数
1
解决办法
2万
查看次数

Angular 2-使用ng2-idle注销

我的问题是,当单击注销按钮ng2-idle时,它继续工作。为了解决此问题,我再次将setIdle和setTimeout函数设置为1秒钟。

但是,当用户转移到登录屏幕时,该应用将花费1秒给出超时。

我想知道在单击调用logout()函数的注销按钮后是否有任何强制超时或结束ng2-idle的方法。

import {Component} from '@angular/core';
import {Router} from "@angular/router";
import {Http, Headers} from "@angular/http";
import {NgClass} from '@angular/common';
import {Observable} from "rxjs/Observable";
import 'rxjs/Rx';
import {HeaderService} from './header.service';
import {Idle, DEFAULT_INTERRUPTSOURCES} from 'ng2-idle/core';

@Component({
    selector: 'my-header',
    templateUrl: './js/app/header/header.component.html',
    styleUrls: ['./js/app/header/header.component.css']
})

export class HeaderComponent {
    nome = localStorage['nome'];
    constructor(private _router: Router, private _http: Http, private _headerService: HeaderService, private idle: Idle) {
        idle.setIdle(5);
        idle.setTimeout(1800);
        idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

        idle.onTimeoutWarning.subscribe((countdown:number) => {
          console.log('TimeoutWarning: ' + countdown);
        });

        idle.onTimeout.subscribe(() => {
          console.log('Timeout');
          localStorage.clear();
          this._router.navigate(['/auth', …
Run Code Online (Sandbox Code Playgroud)

logout ng-idle angular

2
推荐指数
1
解决办法
1万
查看次数