﻿import { Injectable }     from '@angular/core';
import {
    CanActivate, Router,
    ActivatedRouteSnapshot,
    RouterStateSnapshot
}                           from '@angular/router';
import { TfabricaSharedService } from './tfabrica.shared.service';

@Injectable()
export class TfabricaAuthGuardService implements CanActivate {

    constructor(
        public tfabricaSharedService: TfabricaSharedService,
        private router: Router
    ) { }

    canActivate() {
        console.log('AuthGuard#canActivate called');
        if (this.tfabricaSharedService.isLogged()) return true;
        this.router.navigate(['/login']);
        return false;
    }
}