This commit is contained in:
Peter Maquiran
2023-01-12 15:27:09 +01:00
parent 58f9e7eacd
commit 9493179efd
82 changed files with 702 additions and 557 deletions
+13 -67
View File
@@ -1,13 +1,10 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from '../services/auth.service';
import { PermissionService } from '../services/permission.service';
import { LocalstoreService } from '../store/localstore.service';
import { SessionStore } from '../store/session.service';
import { RouteService } from 'src/app/services/route.service'
import { FirstEnterService } from 'src/app/services/first-enter.service'
// import { ModalController } from '@ionic/angular';
import { AlertController, Platform } from '@ionic/angular';
@Injectable({
@@ -31,6 +28,8 @@ export class AuthGuard implements CanActivate {
// if user not active or no session
if(!SessionStore.user.Inactivity || !SessionStore.exist) {
console.log('no session', !SessionStore.user.Inactivity, !SessionStore.exist)
console.log(SessionStore.user)
if(SessionStore.user.LoginPreference == 'Pin') {
this.router.navigate(['/pin']);
} else {
@@ -46,40 +45,10 @@ export class AuthGuard implements CanActivate {
if(pathname.startsWith('/home/agenda')) {
if(this.p.userPermission(this.p.permissionList.Agenda.access)) {
if((SessionStore.user.OwnerCalendars.length != 0 || SessionStore.user.SharedCalendars.length != 0)) {
return true
}
if(['/pin','/login', '/inactivity' , '', '/'].includes(window.location.pathname)) {
this.FirstEnterService.enter()
setTimeout(() => {
// this.modalController.create({
// component: InformationPage,
// componentProps: {
// },
// cssClass: 'discart-expedient-modal',
// backdropDismiss: false
// });
// this.alertController.create({
// cssClass: 'my-custom-class',
// header: 'utilizador não tem calendário',
// buttons: [{
// text: 'Ok',
// handler: () => {
// }
// }]
// }).then( async (alertPopup) => {
// await alertPopup.present();
// })
}, 1000)
}
return false;
return true;
} else {
this.router.navigate(['/login']);
console.log('£1')
return false;
}
@@ -90,45 +59,16 @@ export class AuthGuard implements CanActivate {
return true;
} else {
this.router.navigate(['/login']);
console.log('£2')
return false;
}
}
else if(pathname.startsWith('/home/chat')) {
if(this.p.userPermission(this.p.permissionList.Chat.access)) {
if(!SessionStore.user.ChatData?.data) {
if(['/pin','/login', '/inactivity' , '', '/'].includes(window.location.pathname)) {
this.FirstEnterService.enter()
setTimeout(() => {
// this.modalController.create({
// component: InformationPage,
// componentProps: {
// },
// cssClass: 'discart-expedient-modal',
// backdropDismiss: false
// });
// this.alertController.create({
// cssClass: 'my-custom-class',
// header: 'Serviço temporariamente indisponível',
// buttons: [{
// text: 'Ok',
// handler: () => {
// }
// }]
// }).then( async (alertPopup) => {
// await alertPopup.present();
// })
}, 1000)
}
return false
}
return true;
} else {
console.log("no access to chat")
console.log('£3')
this.router.navigate(['/login']);
return false;
}
@@ -136,6 +76,7 @@ export class AuthGuard implements CanActivate {
if(this.p.userPermission(this.p.permissionList.Actions.access)) {
return true
} else {
console.log('£4')
this.router.navigate(['/login']);
return false
}
@@ -143,13 +84,18 @@ export class AuthGuard implements CanActivate {
if(SessionStore.user.OwnerCalendars.length >= 1 || this.p.userPermission([this.p.permissionList.Gabinete.access])) {
return true
} else {
console.log('£5')
this.router.navigate(['/login']);
return false
}
} else if (pathname == '/') {
console.log('£6')
this.router.navigate(['/login']);
console.log('no path')
return false
} else {
console.log('£7')
console.log('pathname not match')
this.router.navigate(['/login']);
return false
}