Files
doneit-web/src/app/guards/inactivity.guard.ts
T

87 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-08-27 13:39:52 +01:00
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { SessionStore } from '../store/session.service';
2021-09-02 12:17:14 +01:00
import { AlertController, Platform } from '@ionic/angular';
2022-03-29 16:49:51 +01:00
import { PermissionService } from '../services/permission.service';
2021-08-27 13:39:52 +01:00
@Injectable({
providedIn: 'root'
})
export class InactivityGuard implements CanActivate {
constructor(
2021-09-02 12:17:14 +01:00
private router:Router,
private platform: Platform,
2022-04-07 15:57:22 +01:00
public p: PermissionService,
2022-04-02 09:40:09 +01:00
private alertController: AlertController
) {}
2021-08-27 13:39:52 +01:00
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
2022-04-02 09:40:09 +01:00
2021-09-02 12:17:14 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-04-07 15:57:22 +01:00
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
2022-05-30 16:06:28 +01:00
this.router.navigate(['/home/events']);
2022-03-29 16:49:51 +01:00
}
2022-05-30 16:06:28 +01:00
else if(this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)){
2022-03-29 16:49:51 +01:00
this.router.navigate(['/home/chat']);
}
2022-04-08 13:52:00 +01:00
else if(this.p.userPermission(this.p.permissionList.Actions.access)) {
2022-03-29 16:49:51 +01:00
this.router.navigate(['/home/publications']);
2022-05-30 16:06:28 +01:00
} else {
2022-04-02 09:40:09 +01:00
this.alertController.create({
cssClass: 'my-custom-class',
header: 'Utilizador sem acesso a aplicação',
buttons: [{
text: 'Ok',
handler: () => {
2022-04-07 15:57:22 +01:00
2022-04-02 09:40:09 +01:00
}
}]
}).then( async (alertPopup) => {
await alertPopup.present();
})
2022-04-07 15:57:22 +01:00
2022-03-29 16:49:51 +01:00
}
2022-04-07 15:57:22 +01:00
2021-09-02 12:17:14 +01:00
return false
} else if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin ) {
2021-08-27 13:39:52 +01:00
return true
2021-08-27 17:11:05 +01:00
} else if(SessionStore.exist && !SessionStore.user.Inactivity) {
2021-08-27 13:39:52 +01:00
return true
2022-03-29 16:49:51 +01:00
}//Mobile or Tablet without session
else {
2022-04-02 09:40:09 +01:00
2022-04-07 15:57:22 +01:00
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
2022-05-30 16:06:28 +01:00
this.router.navigate(['/home/events']);
2022-03-29 16:49:51 +01:00
}
2022-05-30 16:06:28 +01:00
else if(this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)){
2022-03-29 16:49:51 +01:00
this.router.navigate(['/home/chat']);
}
2022-04-07 15:57:22 +01:00
else if(this.p.userPermission(this.p.permissionList.Actions.access)){
2022-03-29 16:49:51 +01:00
this.router.navigate(['/home/publications']);
2022-05-30 16:06:28 +01:00
} else {
2022-04-02 09:40:09 +01:00
this.alertController.create({
cssClass: 'my-custom-class',
header: 'Utilizador sem acesso a aplicação',
buttons: [{
text: 'Ok',
handler: () => {
2022-04-07 15:57:22 +01:00
2022-04-02 09:40:09 +01:00
}
}]
}).then( async (alertPopup)=>{
await alertPopup.present();
})
2022-03-29 16:49:51 +01:00
}
2021-08-27 13:39:52 +01:00
return false
}
2022-03-29 16:49:51 +01:00
2021-08-27 13:39:52 +01:00
}
2022-03-29 16:49:51 +01:00
2021-08-27 13:39:52 +01:00
}