From 0c80a6d84d9b2adf62657e4ac2ea8c2160aac1c2 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 21 Dec 2022 14:53:01 +0100 Subject: [PATCH 1/2] save --- src/app/guards/inactivity.guard.ts | 48 ++++++++++++++++-------------- src/app/guards/login.guard.ts | 6 ++-- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/app/guards/inactivity.guard.ts b/src/app/guards/inactivity.guard.ts index bf19b3a05..acb8555cc 100644 --- a/src/app/guards/inactivity.guard.ts +++ b/src/app/guards/inactivity.guard.ts @@ -23,7 +23,7 @@ export class InactivityGuard implements CanActivate { console.log('hire inactinity!', state.url) - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + if ((this.platform.is('desktop') || this.platform.is('mobileweb')) && (SessionStore?.user?.Inactivity) ) { if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){ this.router.navigate(['/home/events']); } @@ -64,29 +64,33 @@ export class InactivityGuard implements CanActivate { }//Mobile or Tablet without session else { - if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){ - this.router.navigate(['/home/events']); + if((SessionStore?.user?.Inactivity)) { + if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){ + this.router.navigate(['/home/events']); + } + else if(this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)){ + this.router.navigate(['/home/chat']); + } + else if(this.p.userPermission(this.p.permissionList.Actions.access)){ + this.router.navigate(['/home/publications']); + } else { + this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Utilizador sem acesso a aplicação', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }).then( async (alertPopup)=>{ + await alertPopup.present(); + }) + } + return false } - else if(this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)){ - this.router.navigate(['/home/chat']); - } - else if(this.p.userPermission(this.p.permissionList.Actions.access)){ - this.router.navigate(['/home/publications']); - } else { - this.alertController.create({ - cssClass: 'my-custom-class', - header: 'Utilizador sem acesso a aplicação', - buttons: [{ - text: 'Ok', - handler: () => { - } - }] - }).then( async (alertPopup)=>{ - await alertPopup.present(); - }) - } - return false + } } diff --git a/src/app/guards/login.guard.ts b/src/app/guards/login.guard.ts index e191945c4..dd141113a 100644 --- a/src/app/guards/login.guard.ts +++ b/src/app/guards/login.guard.ts @@ -21,18 +21,20 @@ export class LoginGuard implements CanActivate { if(SessionStore.exist && SessionStore.user.Inactivity && SessionStore.user.LoginPreference != 'Pin' ) { + // enter app this.router.navigate(['/home/events']); return false } else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' && SessionStore.forceToLoginWithForceToLogInWithPassword && !this.platform.is('desktop') && !this.platform.is('mobileweb')) { + // login with password while has pin SessionStore.forceToLoginWithForceToLogInWithPassword = false return true - } else if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin && !this.platform.is('desktop') && !this.platform.is('mobileweb') ) { + } else if(SessionStore.exist && !this.platform.is('desktop') && !this.platform.is('mobileweb') ) { + // go to pin page this.router.navigate(['/pin']); return false } else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' && !this.platform.is('desktop') && !this.platform.is('mobileweb')) { this.router.navigate(['/inactivity']); return false - } else { return true } From a1c58560897ed00069532e0f57e2bd50bfbeb124 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 21 Dec 2022 15:08:55 +0100 Subject: [PATCH 2/2] save --- src/app/guards/auth.guard.ts | 17 +++++++++-------- src/app/guards/inactivity.guard.ts | 7 +++++-- src/app/guards/login.guard.ts | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index f179930b2..6c15122e6 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -22,14 +22,15 @@ export class AuthGuard implements CanActivate { route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { - // if user not active - if(!SessionStore.user.Inactivity) { - this.router.navigate(['/']); - return false - } - // if session doesn't exit - else if(!SessionStore.exist) { - this.router.navigate(['/']); + // if user not active or no session + if(!SessionStore.user.Inactivity || !SessionStore.exist) { + + if(SessionStore.user.LoginPreference == 'Pin') { + this.router.navigate(['/pin']); + } else { + this.router.navigate(['/']); + } + return false } else { diff --git a/src/app/guards/inactivity.guard.ts b/src/app/guards/inactivity.guard.ts index acb8555cc..5118c8a3f 100644 --- a/src/app/guards/inactivity.guard.ts +++ b/src/app/guards/inactivity.guard.ts @@ -23,7 +23,7 @@ export class InactivityGuard implements CanActivate { console.log('hire inactinity!', state.url) - if ((this.platform.is('desktop') || this.platform.is('mobileweb')) && (SessionStore?.user?.Inactivity) ) { + if ( (this.platform.is('desktop') || this.platform.is('mobileweb')) ) { if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){ this.router.navigate(['/home/events']); } @@ -56,7 +56,10 @@ export class InactivityGuard implements CanActivate { } else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin') { // inactivity login return true - } else if (SessionStore.user.LoginPreference != 'Pin' && !SessionStore.user.Inactivity) { + } else if (!SessionStore.user.Inactivity && this.platform.is('mobile')) { + // try to login + return true + } else if (SessionStore.user.LoginPreference != 'Pin' && SessionStore.hasPin) { // no right to be in this page this.router.navigateByUrl('/', { replaceUrl: true }); diff --git a/src/app/guards/login.guard.ts b/src/app/guards/login.guard.ts index dd141113a..b74d01a34 100644 --- a/src/app/guards/login.guard.ts +++ b/src/app/guards/login.guard.ts @@ -28,7 +28,7 @@ export class LoginGuard implements CanActivate { // login with password while has pin SessionStore.forceToLoginWithForceToLogInWithPassword = false return true - } else if(SessionStore.exist && !this.platform.is('desktop') && !this.platform.is('mobileweb') ) { + } else if(SessionStore.exist && this.platform.is('mobile') && SessionStore.user.LoginPreference == 'Pin' ) { // go to pin page this.router.navigate(['/pin']); return false