From f32e9c6dc91d8d737e09aa55269d412063b6bc15 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 17 Sep 2021 19:39:16 +0300 Subject: [PATCH] 139. Login component - test if user is logged in already (#18) --- .../app/component/login/login.component.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/support-portal-frontend/src/app/component/login/login.component.ts b/support-portal-frontend/src/app/component/login/login.component.ts index 643e87d..7497669 100644 --- a/support-portal-frontend/src/app/component/login/login.component.ts +++ b/support-portal-frontend/src/app/component/login/login.component.ts @@ -1,15 +1,31 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; +import {Router} from "@angular/router"; +import {AuthenticationService} from "../../service/authentication.service"; +import {NotificationService} from "../../service/notification.service"; +import {NotificationType} from "../../notification/notification-type"; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) -export class LoginComponent implements OnInit { +export class LoginComponent implements OnInit, OnDestroy { - constructor() { } + constructor(private router: Router, + private authenticationService: AuthenticationService, + private notificationService: NotificationService) { + } ngOnInit(): void { + if (this.authenticationService.isUserLoggedIn()) { + this.router.navigateByUrl("/user/management"); + this.notificationService.notify(NotificationType.INFO, "You are already logged in"); + } else { + // this.router.navigateByUrl("/login"); + } + } + + ngOnDestroy(): void { } }