Ajout un "logout"
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
gears</a></li>
|
gears</a></li>
|
||||||
<li><a routerLink="/newjump" routerLinkActive="active" (click)="toggleMenu()" skipLocationChange>Add a new
|
<li><a routerLink="/newjump" routerLinkActive="active" (click)="toggleMenu()" skipLocationChange>Add a new
|
||||||
jump</a></li>
|
jump</a></li>
|
||||||
|
<li *ngIf="currentUser"><a class="nav-item nav-link" (click)="logout()">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ServiceComm } from '../services/service-comm.service';
|
import { ServiceComm } from '../services/service-comm.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { AuthenticationService } from '../services/authentication.service';
|
||||||
|
import { User } from '../models/user';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -9,8 +12,15 @@ import { ServiceComm } from '../services/service-comm.service';
|
|||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
title = 'app';
|
title = 'app';
|
||||||
showMenu = false;
|
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() {
|
ngOnInit() {
|
||||||
this.serviceComm.componentTitle.subscribe(title => (this.title = title));
|
this.serviceComm.componentTitle.subscribe(title => (this.title = title));
|
||||||
@@ -19,4 +29,10 @@ export class AppComponent implements OnInit {
|
|||||||
toggleMenu() {
|
toggleMenu() {
|
||||||
this.showMenu = !this.showMenu;
|
this.showMenu = !this.showMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
this.authenticationService.logout();
|
||||||
|
this.showMenu = !this.showMenu;
|
||||||
|
this.router.navigate(['/login']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user