import { Injectable , Injector } from '@angular/core' ; import { Router } from "@angular/router" ; import { appInjService } from "./AppInjService" ; import Map = Immutable . Map ; import * as Immutable from "immutable" ; import { ToastrService } from "ngx-toastr" ; export enum FlagsAuth { AuthPass , AuthFailEnterprise , WrongPass , NotEnterprise , Enterprise } @ Injectable ( ) export class AuthService { constructor ( public toastrService ) { } private ubsub : ( ) => void ; private m_authenticated : boolean = false ; public checkAccess ( ) { let injector = appInjService ( ) ; let router = injector . get ( Router ) ; let target = [ '/Login/Login' ] ; this . m_authenticated = true ; if ( this . m_authenticated ) return Promise . resolve ( true ) ; if ( ! this . m_authenticated ) { this . toastrService . error ( 'Sorry user or password are incorrect' ) ; router . navigate ( target ) ; return Promise . resolve ( false ) ; } } ngOnDestroy ( ) { this . ubsub ( ) ; } }