2021-07-26 15:19:03 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
|
import { UserForm } from 'src/app/models/user.model';
|
|
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
|
import { AlertController } from '@ionic/angular';
|
2021-11-05 07:49:01 +01:00
|
|
|
import { NotificationsService } from 'src/app/services/notifications.service';
|
2021-08-27 13:39:52 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2021-11-15 15:29:43 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2022-04-05 17:10:23 +01:00
|
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-inactivity',
|
|
|
|
|
templateUrl: './inactivity.page.html',
|
|
|
|
|
styleUrls: ['./inactivity.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class InactivityPage implements OnInit {
|
|
|
|
|
|
|
|
|
|
username: string = environment.defaultuser;
|
|
|
|
|
password: string = environment.defaultuserpwd;
|
|
|
|
|
userattempt: UserForm;
|
|
|
|
|
code = []
|
|
|
|
|
setPin = false
|
2021-08-27 13:39:52 +01:00
|
|
|
SessionStore = SessionStore
|
2021-08-27 17:11:05 +01:00
|
|
|
enterWithPassword = false
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
constructor(
|
2021-11-05 07:49:01 +01:00
|
|
|
private notificatinsservice: NotificationsService,
|
2021-07-26 15:19:03 +01:00
|
|
|
private router: Router,
|
|
|
|
|
private authService: AuthService,
|
|
|
|
|
private toastService: ToastService,
|
2021-11-15 15:29:43 +01:00
|
|
|
public alertController: AlertController,
|
|
|
|
|
public ThemeService: ThemeService,
|
2022-04-05 17:10:23 +01:00
|
|
|
public p: PermissionService,
|
2021-08-27 13:39:52 +01:00
|
|
|
) {}
|
2021-07-26 15:19:03 +01:00
|
|
|
|
2021-09-02 10:12:18 +01:00
|
|
|
loop = false
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-09-02 10:12:18 +01:00
|
|
|
|
|
|
|
|
// window.addEventListener('resize', (event) => {
|
|
|
|
|
// if(this.router.url != '/login') return false
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-09-02 10:12:18 +01:00
|
|
|
// if(this.loop == false) {
|
|
|
|
|
// this.loop = true
|
|
|
|
|
// this.runloop()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }, true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runloop() {
|
|
|
|
|
// const containerHeight = 651
|
|
|
|
|
|
|
|
|
|
// let circleHeight = document.querySelector('.circle')['offsetHeight']
|
2022-02-08 16:37:32 +01:00
|
|
|
// let circleWidth = document.querySelector('.circle')['offsetWidth']
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-09-02 10:12:18 +01:00
|
|
|
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-09-02 10:12:18 +01:00
|
|
|
|
|
|
|
|
// document.querySelectorAll('.circle').forEach(e=>{
|
|
|
|
|
// e['style']['height'] = (circleHeight -1 )+'px'
|
|
|
|
|
// e['style']['width'] = (circleWidth -1 )+'px'
|
|
|
|
|
// })
|
|
|
|
|
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-09-02 10:12:18 +01:00
|
|
|
// if( window.innerHeight< containerHeight) {
|
|
|
|
|
// setTimeout(()=>{
|
|
|
|
|
// this.runloop()
|
|
|
|
|
// }, 100)
|
|
|
|
|
// } else {
|
|
|
|
|
// this.loop = false
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
async presentAlert(message: string) {
|
|
|
|
|
const alert = await this.alertController.create({
|
|
|
|
|
cssClass: 'my-custom-class',
|
|
|
|
|
header: 'Mensagem do sistema',
|
|
|
|
|
message: message,
|
|
|
|
|
buttons: ['OK']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await alert.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-08-27 15:21:15 +01:00
|
|
|
//Function to validade the login inputs
|
|
|
|
|
validateUsername() {
|
|
|
|
|
return (
|
|
|
|
|
this.username.trim().length > 0
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validatePassword() {
|
|
|
|
|
return (
|
|
|
|
|
this.password.trim().length > 0
|
|
|
|
|
);
|
2021-07-26 15:19:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Login() {
|
|
|
|
|
|
2021-08-27 15:21:15 +01:00
|
|
|
if (this.validateUsername()) {
|
|
|
|
|
if(this.validatePassword()) {
|
|
|
|
|
|
|
|
|
|
this.userattempt = {
|
|
|
|
|
username: this.username,
|
|
|
|
|
password: this.password,
|
|
|
|
|
domainName: environment.domain,
|
|
|
|
|
BasicAuthKey: ""
|
|
|
|
|
}
|
2021-09-02 12:17:14 +01:00
|
|
|
let attempt = await this.authService.login(this.userattempt, {saveSession: false})
|
2021-08-27 15:21:15 +01:00
|
|
|
|
|
|
|
|
if (attempt) {
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2022-04-05 17:10:23 +01:00
|
|
|
|
2021-08-27 15:21:15 +01:00
|
|
|
// if current attemp is equal to the current user
|
|
|
|
|
if (attempt.UserId == SessionStore.user.UserId) {
|
|
|
|
|
await this.authService.SetSession(attempt, this.userattempt);
|
2022-04-05 17:10:23 +01:00
|
|
|
|
|
|
|
|
if(this.p.userPermission(this.p.permissionList.Chat.access)){
|
|
|
|
|
this.authService.loginChat();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 10:27:00 +01:00
|
|
|
this.getToken();
|
2021-08-30 11:41:21 +01:00
|
|
|
SessionStore.setInativity(true)
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-08-27 17:11:05 +01:00
|
|
|
this.goback()
|
2021-08-27 15:21:15 +01:00
|
|
|
} else {
|
|
|
|
|
SessionStore.delete()
|
2021-08-30 11:07:49 +01:00
|
|
|
window.localStorage.clear();
|
2021-08-27 15:21:15 +01:00
|
|
|
await this.authService.SetSession(attempt, this.userattempt);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 17:11:05 +01:00
|
|
|
this.enterWithPassword = false
|
2021-08-27 15:21:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-11-09 15:37:59 +01:00
|
|
|
this.toastService._badRequest('Por favor, insira a sua palavra-passe');
|
2021-08-27 15:21:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-11-09 15:37:59 +01:00
|
|
|
this.toastService._badRequest('Por favor, insira o seu nome de utilizador');
|
2021-08-27 15:21:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-27 09:48:51 +01:00
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
getToken() {
|
2021-11-05 07:49:01 +01:00
|
|
|
this.notificatinsservice.requestPermissions();
|
|
|
|
|
this.notificatinsservice.registrationError();
|
|
|
|
|
this.notificatinsservice.getAndpostToken(this.username);
|
2021-07-26 15:19:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCode(code: string) {
|
|
|
|
|
|
|
|
|
|
if(this.code.length < 4) {
|
|
|
|
|
this.code.push(code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.code.length == 4) {
|
|
|
|
|
|
2021-08-27 13:39:52 +01:00
|
|
|
if(!SessionStore.hasPin) {
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-07-26 15:19:03 +01:00
|
|
|
this.storePin()
|
|
|
|
|
} else {
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-07-26 15:19:03 +01:00
|
|
|
this.pinLogin()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearCode() {
|
|
|
|
|
this.code =[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pinLogin() {
|
|
|
|
|
|
|
|
|
|
const code = this.code.join('')
|
|
|
|
|
|
2021-08-27 13:39:52 +01:00
|
|
|
if( SessionStore.validatePin(code)) {
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-08-31 10:43:38 +01:00
|
|
|
SessionStore.setInativity(true)
|
2021-08-27 17:11:05 +01:00
|
|
|
this.goback()
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2022-04-02 09:40:09 +01:00
|
|
|
setTimeout(() => {
|
2021-08-31 10:43:38 +01:00
|
|
|
this.clearCode()
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
} else {
|
2021-11-09 15:37:59 +01:00
|
|
|
this.toastService._badRequest('Pin incorreto')
|
2021-07-26 15:19:03 +01:00
|
|
|
this.code = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 17:11:05 +01:00
|
|
|
goback() {
|
|
|
|
|
const pathName = this.SessionStore.user.UrlBeforeInactivity
|
2021-08-31 10:27:00 +01:00
|
|
|
if(pathName) {
|
2021-11-25 15:50:41 +01:00
|
|
|
this.router.navigate([pathName],{replaceUrl: true});
|
2021-08-31 10:27:00 +01:00
|
|
|
} else {
|
2022-04-02 09:40:09 +01:00
|
|
|
|
2022-04-22 15:03:09 +01:00
|
|
|
setTimeout(() => {
|
2022-04-07 16:22:33 +01:00
|
|
|
|
|
|
|
|
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
|
2022-04-08 10:57:38 +01:00
|
|
|
//When user has got access to Agenda but does not have their own calendar, goes to Agenda
|
|
|
|
|
if(this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0){
|
|
|
|
|
this.router.navigate(['/home/agenda']);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
}
|
2022-04-07 16:22:33 +01:00
|
|
|
}
|
2022-04-08 10:57:38 +01:00
|
|
|
//If user has access permission to both Chat and Action, goes to Chat by default.
|
2022-04-07 17:51:47 +01:00
|
|
|
else if((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)){
|
2022-04-07 16:22:33 +01:00
|
|
|
this.router.navigate(['/home/chat']);
|
|
|
|
|
}
|
|
|
|
|
else if(this.p.userPermission(this.p.permissionList.Actions.access)){
|
|
|
|
|
this.router.navigate(['/home/publications']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-02 09:40:09 +01:00
|
|
|
}, 5000)
|
2022-04-07 16:22:33 +01:00
|
|
|
|
2021-08-31 10:27:00 +01:00
|
|
|
}
|
2022-02-08 16:37:32 +01:00
|
|
|
|
2021-08-27 17:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
storePin() {
|
|
|
|
|
|
2022-04-22 15:03:09 +01:00
|
|
|
setTimeout(() => {
|
2022-04-02 09:40:09 +01:00
|
|
|
const code = this.code.join('');
|
|
|
|
|
SessionStore.setPin(code);
|
2022-04-07 16:22:33 +01:00
|
|
|
|
|
|
|
|
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
|
2022-04-08 10:57:38 +01:00
|
|
|
//When user has got access to Agenda but does not have their own calendar, goes to Agenda
|
|
|
|
|
if(this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0){
|
|
|
|
|
this.router.navigate(['/home/agenda']);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
}
|
2022-04-07 16:22:33 +01:00
|
|
|
}
|
2022-04-08 10:57:38 +01:00
|
|
|
//If user has access permission to both Chat and Action, goes to Chat by default.
|
2022-04-07 17:51:47 +01:00
|
|
|
else if((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)){
|
2022-04-07 16:22:33 +01:00
|
|
|
this.router.navigate(['/home/chat']);
|
|
|
|
|
}
|
|
|
|
|
else if(this.p.userPermission(this.p.permissionList.Actions.access)){
|
|
|
|
|
this.router.navigate(['/home/publications']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, 5000)
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 17:11:05 +01:00
|
|
|
enterWithPasswordButton() {
|
|
|
|
|
this.enterWithPassword = true
|
2022-06-24 16:18:25 +01:00
|
|
|
this.router.navigate(['/']);
|
2021-08-27 17:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
}
|