remove chat data and ownerCalendar

This commit is contained in:
Peter Maquiran
2024-11-06 08:24:37 +01:00
parent 52d333ad16
commit ecb2f6c08e
39 changed files with 1845 additions and 264 deletions
@@ -0,0 +1,216 @@
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';
import { NotificationsService } from 'src/app/services/notifications.service';
import { SessionStore} from 'src/app/module/user/domain/service/session.service'
import { ThemeService } from 'src/app/services/theme.service';
import { PermissionService } from 'src/app/services/permission.service';
@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
SessionStore = SessionStore
enterWithPassword = false
constructor(
private notificatinsservice: NotificationsService,
private router: Router,
private authService: AuthService,
private toastService: ToastService,
public alertController: AlertController,
public ThemeService: ThemeService,
public p: PermissionService,
) { }
loop = false
ngOnInit() { }
runloop() {
}
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();
}
//Function to validade the login inputs
validateUsername() {
return (
this.username.trim().length > 0
);
}
validatePassword() {
return (
this.password.trim().length > 0
);
}
async Login() {
if (this.validateUsername()) {
if (this.validatePassword()) {
this.userattempt = {
username: this.username,
password: this.password,
domainName: environment.domain,
BasicAuthKey: ""
}
let attempt = await this.authService.login(this.userattempt, { saveSession: false })
if (attempt) {
// if current attemp is equal to the current user
if (attempt.UserId == SessionStore.user.wxUserId) {
await this.authService.SetSession(attempt, this.userattempt);
if (this.p.userPermission(this.p.permissionList.Chat.access)) {
// this.authService.loginChat();
}
this.getToken();
SessionStore.setInativity(true)
this.goback()
} else {
SessionStore.delete()
window.localStorage.clear();
SessionStore.setInativity(true)
await this.authService.SetSession(attempt, this.userattempt);
}
this.enterWithPassword = false
}
}
else {
this.toastService._badRequest('Por favor, insira a sua palavra-passe');
}
}
else {
this.toastService._badRequest('Por favor, insira o seu nome de utilizador');
}
}
getToken() {
this.notificatinsservice.requestPermissions();
this.notificatinsservice.registrationError();
// this.notificatinsservice.getAndpostToken(this.username);
}
setCode(code: string) {
if (this.code.length < 4) {
this.code.push(code)
}
if (this.code.length == 4) {
if (!SessionStore.hasPin) {
//
this.storePin()
this.pinLogin()
} else {
this.pinLogin()
}
}
}
clearCode() {
this.code = []
}
pinLogin() {
const code = this.code.join('')
if (SessionStore.validatePin(code)) {
SessionStore.setInativity(true)
this.goback()
setTimeout(() => {
this.clearCode()
}, 3000)
} else {
this.toastService._badRequest('Pin incorreto')
this.code = []
}
}
goback() {
const pathName = this.SessionStore.preference.UrlBeforeInactivity
if (pathName) {
this.router.navigate([pathName], { replaceUrl: true });
} else {
setTimeout(() => {
if (this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)) {
//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) {
if (this.p.userPermission(this.p.permissionList.Agenda.access)) {
this.router.navigate(['/home/agenda']);
}
else {
this.router.navigate(['/home/events']);
}
}
//If user has access permission to both Chat and Action, goes to Chat by default.
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)) {
this.router.navigate(['/home/chat']);
}
else if (this.p.userPermission(this.p.permissionList.Actions.access)) {
this.router.navigate(['/home/publications']);
}
}, 100)
}
}
storePin() {
const code = this.code.join('');
SessionStore.setPin(code);
}
enterWithPasswordButton() {
this.enterWithPassword = true
SessionStore.forceToLoginWithForceToLogInWithPassword = true
this.router.navigate(['/']);
}
}