Added logout
Change-Id: I1c01af0c2575e56b795514d5af56bd0fbe4f3133
diff --git a/src/app/components/logout/logout.component.ts b/src/app/components/logout/logout.component.ts
new file mode 100644
index 0000000..199cc10
--- /dev/null
+++ b/src/app/components/logout/logout.component.ts
@@ -0,0 +1,33 @@
+/// <reference path="../../../../typings/index.d.ts"/>
+import {Component, OnInit} from '@angular/core';
+import {Router} from '@angular/router';
+import {AuthService} from '../../services/rest/auth.service';
+
+@Component({
+ selector: 'xos-logout',
+ template: `
+ <button *ngIf="show" (click)="logout()">Logout</button>
+ `,
+ providers: [AuthService],
+})
+export class LogoutComponent implements OnInit {
+ public show: boolean = false;
+ constructor(private AuthService: AuthService, private router: Router) {
+ }
+
+ ngOnInit() {
+ if (this.AuthService.isAuthenticated()) {
+ this.show = true;
+ }
+ }
+
+ logout() {
+ this.AuthService.logout()
+ .subscribe(
+ () => {
+ this.router.navigate(['/login']);
+ }
+ );
+ }
+}
+