Matteo Scandolo | 8b9f164 | 2016-12-05 17:08:26 -0800 | [diff] [blame^] | 1 | /// <reference path="../../../../typings/index.d.ts"/> |
| 2 | import {Component, OnInit} from '@angular/core'; |
| 3 | import {Router} from '@angular/router'; |
| 4 | import {AuthService} from '../../services/rest/auth.service'; |
| 5 | |
| 6 | @Component({ |
| 7 | selector: 'xos-logout', |
| 8 | template: ` |
| 9 | <button *ngIf="show" (click)="logout()">Logout</button> |
| 10 | `, |
| 11 | providers: [AuthService], |
| 12 | }) |
| 13 | export class LogoutComponent implements OnInit { |
| 14 | public show: boolean = false; |
| 15 | constructor(private AuthService: AuthService, private router: Router) { |
| 16 | } |
| 17 | |
| 18 | ngOnInit() { |
| 19 | if (this.AuthService.isAuthenticated()) { |
| 20 | this.show = true; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | logout() { |
| 25 | this.AuthService.logout() |
| 26 | .subscribe( |
| 27 | () => { |
| 28 | this.router.navigate(['/login']); |
| 29 | } |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 | |