import {Injectable, OnInit} from '@angular/core';
import {CanActivateChild, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {Transfer} from './transfer';

@Injectable()
export class Auth implements CanActivateChild, OnInit {
    public login = false;

    constructor(private transfer: Transfer) {
    }

    ngOnInit() {
    }

    canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        if (window.localStorage.getItem('token')) {
            return true;
        } else {
            this.transfer.transfer({
                url: '/login',
                query: '',
                hash: ''
            });
            return false;
        }
    }
}
