From 7fa348cab8dc9d975d0beb0963ac41a99bfa03c2 Mon Sep 17 00:00:00 2001 From: Ratnadeep Rajendra Kharade <92khra1mst@hft-stuttgart.de> Date: Thu, 28 Nov 2019 23:36:04 +0100 Subject: [PATCH] Removed navigation menu from login page and handled session condition. --- src/app/app.component.html | 2 +- src/app/app.component.ts | 19 ++++++++++++++++++- src/app/auth/login/login.page.ts | 2 -- src/app/rest.service.ts | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index fffda45..b8ca619 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,6 +1,6 @@ - + Menu diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5da945e..275e977 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,10 @@ import { Component } from '@angular/core'; import { Platform } from '@ionic/angular'; import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { StatusBar } from '@ionic-native/status-bar/ngx'; +import { Storage } from '@ionic/storage'; +import { Router } from '@angular/router'; + +import { RestService } from './rest.service'; @Component({ selector: 'app-root', @@ -10,6 +14,9 @@ import { StatusBar } from '@ionic-native/status-bar/ngx'; styleUrls: ['app.component.scss'] }) export class AppComponent { + + + public appPages = [ { title: 'Home', @@ -26,9 +33,19 @@ export class AppComponent { constructor( private platform: Platform, private splashScreen: SplashScreen, - private statusBar: StatusBar + private statusBar: StatusBar, + public restService: RestService, + private storage: Storage, + private router: Router ) { this.initializeApp(); + this.storage.get('token').then((token) => { + if(token === "") { + this.router.navigateByUrl('/login'); + } else { + this.restService.isUserLoggedIn = true; + } + }); } initializeApp() { diff --git a/src/app/auth/login/login.page.ts b/src/app/auth/login/login.page.ts index 7289431..5f20f04 100644 --- a/src/app/auth/login/login.page.ts +++ b/src/app/auth/login/login.page.ts @@ -46,7 +46,5 @@ export class LoginPage implements OnInit { } register() { this.router.navigateByUrl('/register'); - - } } diff --git a/src/app/rest.service.ts b/src/app/rest.service.ts index d015623..e6e4ac6 100644 --- a/src/app/rest.service.ts +++ b/src/app/rest.service.ts @@ -6,11 +6,13 @@ import { Storage } from '@ionic/storage'; }) export class RestService { + public isUserLoggedIn = false; + constructor(private storage: Storage) { } setToken(token) { - // set a key/value this.storage.set('token', token); + this.isUserLoggedIn = true; } getToken() { -- GitLab