131.3. Notify user to log in (#16)
This commit is contained in:
@ -2,13 +2,19 @@ import {Injectable} from '@angular/core';
|
|||||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {AuthenticationService} from "../service/authentication.service";
|
import {AuthenticationService} from "../service/authentication.service";
|
||||||
|
import {NotificationService} from "../service/notification.service";
|
||||||
|
import {NotificationType} from "../notification/notification-type";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationGuard implements CanActivate {
|
export class AuthenticationGuard implements CanActivate {
|
||||||
|
|
||||||
constructor(private authenticationService: AuthenticationService, private router: Router) {
|
constructor(
|
||||||
|
private authenticationService: AuthenticationService,
|
||||||
|
private router: Router,
|
||||||
|
private notificationService: NotificationService
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(
|
canActivate(
|
||||||
@ -18,12 +24,12 @@ export class AuthenticationGuard implements CanActivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isUserLoggedIn(): boolean {
|
private isUserLoggedIn(): boolean {
|
||||||
if( this.authenticationService.isUserLoggedIn())
|
if (this.authenticationService.isUserLoggedIn())
|
||||||
return true;
|
return true;
|
||||||
else {
|
else {
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
|
|
||||||
//todo - send notification to user
|
this.notificationService.notify(NotificationType.ERROR, `You need to log in to access this page`.toUpperCase());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user