From 11d4127c209aee91f06eceabcb8ec8c4f399d457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Fri, 13 Mar 2020 16:30:41 +0100 Subject: [PATCH] Ajout un "logout" --- .../skydivelogs-app/src/app/app.component.html | 1 + Front/skydivelogs-app/src/app/app.component.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Front/skydivelogs-app/src/app/app.component.html b/Front/skydivelogs-app/src/app/app.component.html index bd02e3a..abe0d39 100644 --- a/Front/skydivelogs-app/src/app/app.component.html +++ b/Front/skydivelogs-app/src/app/app.component.html @@ -27,6 +27,7 @@ gears
  • Add a new jump
  • +
  • Logout
  • diff --git a/Front/skydivelogs-app/src/app/app.component.ts b/Front/skydivelogs-app/src/app/app.component.ts index 5cd9283..194e3fa 100644 --- a/Front/skydivelogs-app/src/app/app.component.ts +++ b/Front/skydivelogs-app/src/app/app.component.ts @@ -1,5 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { ServiceComm } from '../services/service-comm.service'; +import { Router } from '@angular/router'; +import { AuthenticationService } from '../services/authentication.service'; +import { User } from '../models/user'; @Component({ selector: 'app-root', @@ -9,8 +12,15 @@ import { ServiceComm } from '../services/service-comm.service'; export class AppComponent implements OnInit { title = 'app'; showMenu = false; + currentUser: User; - constructor(private serviceComm: ServiceComm) { } + constructor( + private router: Router, + private authenticationService: AuthenticationService, + private serviceComm: ServiceComm + ) { + this.authenticationService.currentUser.subscribe(x => this.currentUser = x); + } ngOnInit() { this.serviceComm.componentTitle.subscribe(title => (this.title = title)); @@ -19,4 +29,10 @@ export class AppComponent implements OnInit { toggleMenu() { this.showMenu = !this.showMenu; } + + logout() { + this.authenticationService.logout(); + this.showMenu = !this.showMenu; + this.router.navigate(['/login']); + } }