Explorar el Código

if another tab from the same browser logged in as a different user, we logout others.

tags/2.037
Patrick Sun hace 4 años
padre
commit
6ec661254c
Se han modificado 1 ficheros con 13 adiciones y 9 borrados
  1. +13
    -9
      src/app/app.component.ts

+ 13
- 9
src/app/app.component.ts Ver fichero

@@ -1,13 +1,12 @@
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { Subscription } from 'rxjs';
import { LoanEditComponent } from './loan-edit/loan-edit.component';

import { AuthService } from './service/auth.service';
import { MenuService } from './service/menu.service';

import {WebSocketService} from './websocket';
import {AppConfig} from './app.config';
import {Title} from '@angular/platform-browser';
import {WsLoginEventModel} from './models/websocket/ws.login.event.model';
import {SessionService} from './service/session.service';

@Component({
selector: 'app-root',
@@ -25,7 +24,7 @@ export class AppComponent implements OnInit , OnDestroy {

constructor(private menuService: MenuService,
private authService: AuthService,
private config: AppConfig,
private ss: SessionService,
private wsService: WebSocketService,
private titleService: Title){
this.webSocketSubscription = wsService.subscribe(m => {
@@ -33,7 +32,7 @@ export class AppComponent implements OnInit , OnDestroy {
});

this.wsLoginSub = this.wsService.LoginEvent.subscribe( m => {
console.log('login event ', m);
this.onWSLogin(m);
});

this.titleService.setTitle(this.title);
@@ -48,15 +47,12 @@ export class AppComponent implements OnInit , OnDestroy {

listenToMenuEvent(): void {
this.menuItemSub = this.menuService.itemClicked.subscribe(
(item:any) =>{
(item: any) => {
// console.log("emit on select : " + item.text);
if ( item.popup === 'loanEdit'){
// this.loanEdit.somedata = '' + Math.random() + 'changed';
// this.loanEdit.open('dialog');
}
}
);

}

ngOnDestroy(): void {
@@ -64,4 +60,12 @@ export class AppComponent implements OnInit , OnDestroy {
this.wsLoginSub.unsubscribe();
}

onWSLogin(e: WsLoginEventModel): void {
if ( e.Mid === this.ss.loggedIn.machineId && e.Sid === this.ss.loggedIn.session ){
if ( e.Uid !== this.ss.loggedIn.User.Id && e.Uid !== '') {
this.ss.logout();
}
}
}

}

Cargando…
Cancelar
Guardar