2020-08-05 15:39:16 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
2020-08-06 14:31:07 +01:00
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
2021-07-01 09:52:36 +01:00
|
|
|
import { UserForm } from 'src/app/models/user.model';
|
2020-08-21 10:44:43 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2020-08-24 12:55:10 +01:00
|
|
|
import { environment } from 'src/environments/environment';
|
2021-07-01 09:52:36 +01:00
|
|
|
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-09-27 16:23:41 +01:00
|
|
|
import { ClearStoreService } from 'src/app/services/clear-store.service';
|
2021-09-28 11:31:10 +01:00
|
|
|
import { ChangeProfileService } from 'src/app/services/change-profile.service';
|
2021-10-26 15:27:25 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2022-03-29 16:49:51 +01:00
|
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
2022-07-21 18:05:29 +01:00
|
|
|
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm';
|
2022-09-30 15:13:36 +01:00
|
|
|
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
|
|
|
|
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
2022-07-22 15:52:10 +01:00
|
|
|
import { ChatService } from 'src/app/services/chat.service';
|
2023-10-11 16:20:42 +01:00
|
|
|
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
2022-12-22 12:35:45 +01:00
|
|
|
import { Platform } from '@ionic/angular';
|
2022-12-26 15:41:11 +01:00
|
|
|
import { FirstEnterService } from '../../services/first-enter.service';
|
2022-12-30 14:31:19 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2023-07-10 12:32:01 +01:00
|
|
|
import { CPSession } from 'src/app/store/documentManagement';
|
2023-08-29 16:05:32 +01:00
|
|
|
import { StorageService } from 'src/app/services/storage.service';
|
2024-02-22 11:40:06 +01:00
|
|
|
import { DeviceService } from 'src/app/services/device.service'
|
2024-04-11 09:13:30 +01:00
|
|
|
import { Cy } from 'cypress/enum'
|
2020-08-05 15:39:16 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-login',
|
|
|
|
|
templateUrl: './login.page.html',
|
|
|
|
|
styleUrls: ['./login.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class LoginPage implements OnInit {
|
|
|
|
|
|
2020-08-19 23:47:11 +01:00
|
|
|
logstatus: boolean;
|
2024-01-30 14:27:23 +01:00
|
|
|
username: string = environment.defaultuser;
|
2020-08-24 12:55:10 +01:00
|
|
|
password: string = environment.defaultuserpwd;
|
2021-05-10 14:53:46 +01:00
|
|
|
userattempt: UserForm;
|
2021-05-28 14:41:56 +01:00
|
|
|
code = []
|
|
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
hasPin: boolean
|
2021-07-01 09:52:36 +01:00
|
|
|
loginPreference: string
|
2021-08-27 13:39:52 +01:00
|
|
|
|
2022-03-29 16:49:51 +01:00
|
|
|
sessionStore = SessionStore;
|
2022-05-02 16:19:59 +01:00
|
|
|
showPassword = false;
|
|
|
|
|
passwordIcon = "eye";
|
2024-04-11 09:13:30 +01:00
|
|
|
Cy = Cy
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-11 04:11:42 +01:00
|
|
|
constructor(
|
2021-11-05 07:49:01 +01:00
|
|
|
private notificatinsservice: NotificationsService,
|
2021-01-22 16:03:05 +01:00
|
|
|
private router: Router,
|
2020-08-21 10:44:43 +01:00
|
|
|
private authService: AuthService,
|
2020-08-25 10:37:41 +01:00
|
|
|
private toastService: ToastService,
|
2021-09-21 06:09:41 +01:00
|
|
|
public alertController: AlertController,
|
2021-09-28 11:31:10 +01:00
|
|
|
private clearStoreService: ClearStoreService,
|
2021-10-21 15:47:00 +01:00
|
|
|
private changeProfileService: ChangeProfileService,
|
2021-10-27 07:11:58 +01:00
|
|
|
public ThemeService: ThemeService,
|
2022-04-05 17:10:23 +01:00
|
|
|
public p: PermissionService,
|
2022-09-30 15:13:36 +01:00
|
|
|
private RochetChatConnectorService: RochetChatConnectorService,
|
|
|
|
|
public ChatSystemService: ChatSystemService,
|
2022-12-22 12:35:45 +01:00
|
|
|
private ChatService: ChatService,
|
|
|
|
|
private platform: Platform,
|
2022-12-30 14:31:19 +01:00
|
|
|
private FirstEnterService: FirstEnterService,
|
2023-10-09 14:15:21 +01:00
|
|
|
private storage: Storage,
|
2023-08-29 16:05:32 +01:00
|
|
|
private storageService: StorageService,
|
2024-02-22 11:40:06 +01:00
|
|
|
private NotificationHolderService: NotificationHolderService,
|
|
|
|
|
private DeviceService: DeviceService
|
2023-10-09 14:15:21 +01:00
|
|
|
) { }
|
2021-07-01 09:52:36 +01:00
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
ngOnInit() { }
|
2021-05-28 14:41:56 +01:00
|
|
|
|
2022-05-02 16:19:59 +01:00
|
|
|
togglePassword() {
|
|
|
|
|
this.showPassword = !this.showPassword;
|
|
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
if (this.passwordIcon == "eye") {
|
2022-05-02 16:19:59 +01:00
|
|
|
this.passwordIcon = "eye-off";
|
|
|
|
|
} else {
|
|
|
|
|
this.passwordIcon = "eye";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 13:46:13 +01:00
|
|
|
//Function to validade the login inputs
|
2021-06-09 13:34:55 +01:00
|
|
|
validateUsername() {
|
2020-08-06 14:31:07 +01:00
|
|
|
return (
|
2021-01-22 16:03:05 +01:00
|
|
|
this.username.trim().length > 0
|
2021-06-09 13:34:55 +01:00
|
|
|
);
|
|
|
|
|
}
|
2021-07-22 14:40:29 +01:00
|
|
|
|
2021-06-09 13:34:55 +01:00
|
|
|
validatePassword() {
|
|
|
|
|
return (
|
|
|
|
|
this.password.trim().length > 0
|
2021-01-22 16:03:05 +01:00
|
|
|
);
|
2020-08-07 10:31:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-22 16:03:05 +01:00
|
|
|
async presentAlert(message: string) {
|
2020-08-25 10:37:41 +01:00
|
|
|
const alert = await this.alertController.create({
|
|
|
|
|
cssClass: 'my-custom-class',
|
|
|
|
|
header: 'Mensagem do sistema',
|
|
|
|
|
message: message,
|
|
|
|
|
buttons: ['OK']
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2020-08-25 10:37:41 +01:00
|
|
|
await alert.present();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 09:48:14 +01:00
|
|
|
getToken() {
|
2023-01-16 09:06:12 +01:00
|
|
|
this.notificatinsservice.requestPermissions();
|
|
|
|
|
this.notificatinsservice.registrationError();
|
2023-10-09 14:15:21 +01:00
|
|
|
// this.notificatinsservice.getAndpostToken(this.username);
|
2021-04-09 09:48:14 +01:00
|
|
|
}
|
2021-01-22 16:03:05 +01:00
|
|
|
|
|
|
|
|
async Login() {
|
2022-12-17 19:23:01 +01:00
|
|
|
|
2022-12-22 12:35:45 +01:00
|
|
|
|
2021-06-09 13:34:55 +01:00
|
|
|
if (this.validateUsername()) {
|
2023-10-09 14:15:21 +01:00
|
|
|
if (this.validatePassword()) {
|
2021-07-01 09:52:36 +01:00
|
|
|
|
2023-11-08 08:58:13 +01:00
|
|
|
let newUserName = ""
|
|
|
|
|
if (this.usernameAsDomain(environment.domain, this.username.trim())) {
|
|
|
|
|
newUserName = this.username.trim();
|
|
|
|
|
} else {
|
|
|
|
|
newUserName = this.username.trim() + "@" + environment.domain;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 13:34:55 +01:00
|
|
|
this.userattempt = {
|
2023-11-08 08:58:13 +01:00
|
|
|
username: newUserName.trim(),
|
2022-05-02 16:19:59 +01:00
|
|
|
password: this.password.trim(),
|
2021-06-09 13:34:55 +01:00
|
|
|
domainName: environment.domain,
|
|
|
|
|
BasicAuthKey: ""
|
2021-05-31 14:21:19 +01:00
|
|
|
}
|
2021-12-29 15:48:35 +01:00
|
|
|
|
2021-09-27 16:23:41 +01:00
|
|
|
const loader = this.toastService.loading()
|
2021-09-02 12:17:14 +01:00
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
let attempt = await this.authService.login(this.userattempt, { saveSession: false })
|
2023-11-29 12:17:52 +01:00
|
|
|
/* const data = await this.authService.loginContenteProduction(this.userattempt, { saveSession: true }) */
|
2021-07-22 14:40:29 +01:00
|
|
|
|
2021-12-29 15:48:35 +01:00
|
|
|
|
2023-09-28 09:02:15 +01:00
|
|
|
loader.remove()
|
2023-08-10 16:46:55 +01:00
|
|
|
|
2021-06-09 14:00:14 +01:00
|
|
|
if (attempt) {
|
2022-01-14 10:35:54 +01:00
|
|
|
if (attempt.UserId == SessionStore.user.UserId) {
|
2022-03-29 16:49:51 +01:00
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
await this.authService.SetSession(attempt, this.userattempt);
|
2023-11-29 12:17:52 +01:00
|
|
|
/* CPSession.save(data) */
|
2023-01-24 15:56:47 +01:00
|
|
|
this.changeProfileService.run();
|
2022-04-05 17:10:23 +01:00
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
if (attempt.ChatData) {
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2024-03-11 10:23:33 +01:00
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
await MessageModel.deleteAll();
|
|
|
|
|
await DeleteMessageModel.deleteAll();
|
|
|
|
|
this.ChatSystemService.clearChat();
|
|
|
|
|
this.NotificationHolderService.clear()
|
|
|
|
|
await this.authService.loginToChatWs();
|
|
|
|
|
this.ChatService.setheader()
|
|
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
|
console.log("faild to clear chat")
|
|
|
|
|
}
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2022-04-19 16:48:06 +01:00
|
|
|
}
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2022-12-19 18:38:53 +01:00
|
|
|
this.changeProfileService.runLogin();
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2023-08-29 16:05:32 +01:00
|
|
|
this.getToken();
|
2021-09-21 06:09:41 +01:00
|
|
|
SessionStore.setInativity(true);
|
2023-09-28 09:02:15 +01:00
|
|
|
SessionStore.hasPassLogin = true;
|
2021-12-29 15:48:35 +01:00
|
|
|
|
2022-03-29 16:49:51 +01:00
|
|
|
this.goback();
|
|
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
} else {
|
2021-09-27 16:23:41 +01:00
|
|
|
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2022-09-30 15:13:36 +01:00
|
|
|
this.RochetChatConnectorService.logout();
|
2022-03-29 16:49:51 +01:00
|
|
|
this.clearStoreService.clear();
|
2022-09-30 15:13:36 +01:00
|
|
|
this.ChatSystemService.clearChat();
|
2023-10-11 16:20:42 +01:00
|
|
|
this.NotificationHolderService.clear()
|
2022-03-29 16:49:51 +01:00
|
|
|
SessionStore.delete();
|
2021-09-02 12:17:14 +01:00
|
|
|
window.localStorage.clear();
|
2022-12-22 12:35:45 +01:00
|
|
|
await MessageModel.deleteAll();
|
|
|
|
|
await DeleteMessageModel.deleteAll();
|
2023-07-10 12:32:01 +01:00
|
|
|
CPSession.clear();
|
2022-12-30 14:31:19 +01:00
|
|
|
this.storage.clear();
|
2021-09-28 11:31:10 +01:00
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
await this.authService.SetSession(attempt, this.userattempt);
|
2023-11-29 12:17:52 +01:00
|
|
|
/* CPSession.save(data) */
|
2023-07-13 12:11:28 +01:00
|
|
|
this.changeProfileService.run();
|
2022-04-02 09:40:09 +01:00
|
|
|
|
2023-09-28 09:02:15 +01:00
|
|
|
|
|
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
if (attempt.ChatData) {
|
2022-04-05 17:10:23 +01:00
|
|
|
await this.authService.loginToChatWs();
|
2022-09-27 14:52:01 +01:00
|
|
|
this.ChatService.setheader();
|
2022-04-19 16:48:06 +01:00
|
|
|
}
|
2023-08-29 16:05:32 +01:00
|
|
|
this.storageService.remove("Notifications")
|
2023-10-09 14:15:21 +01:00
|
|
|
this.getToken();
|
2022-03-29 16:49:51 +01:00
|
|
|
|
2023-10-09 14:15:21 +01:00
|
|
|
if (!this.platform.is('desktop') && !this.platform.is('mobileweb')) {
|
|
|
|
|
if (this.sessionStore.hasPin) {
|
2022-12-22 12:35:45 +01:00
|
|
|
this.router.navigateByUrl('/home/events');
|
|
|
|
|
} else {
|
|
|
|
|
this.router.navigateByUrl('/pin', { replaceUrl: true });
|
|
|
|
|
}
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2022-12-22 12:35:45 +01:00
|
|
|
} else {
|
|
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 09:02:15 +01:00
|
|
|
SessionStore.hasPassLogin = true;
|
|
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
}
|
2023-09-28 09:02:15 +01:00
|
|
|
}/*
|
2022-02-16 13:52:32 +01:00
|
|
|
else{
|
|
|
|
|
this.toastService._badRequest('Ocorreu um problema por favor valide o username e password');
|
2023-03-09 09:09:10 +01:00
|
|
|
} */
|
2021-01-22 16:03:05 +01:00
|
|
|
}
|
2021-07-01 09:52:36 +01:00
|
|
|
else {
|
2021-11-09 15:37:59 +01:00
|
|
|
this.toastService._badRequest('Por favor, insira a sua palavra-passe');
|
2021-02-25 10:47:13 +01:00
|
|
|
}
|
2021-01-22 16:03:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-11-09 15:37:59 +01:00
|
|
|
this.toastService._badRequest('Por favor, insira o seu nome de utilizador');
|
2021-01-22 16:03:05 +01:00
|
|
|
}
|
2022-04-07 14:24:07 +01:00
|
|
|
|
2022-04-07 15:57:22 +01:00
|
|
|
|
2020-08-05 15:39:16 +01:00
|
|
|
}
|
2021-05-28 14:41:56 +01:00
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
goback() {
|
|
|
|
|
const pathName = SessionStore.user.UrlBeforeInactivity
|
2023-10-09 14:15:21 +01:00
|
|
|
if (pathName) {
|
2021-09-02 12:17:14 +01:00
|
|
|
this.router.navigate([pathName]);
|
|
|
|
|
} else {
|
2023-10-09 14:15:21 +01:00
|
|
|
if (this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)) {
|
2022-12-26 17:04:20 +01:00
|
|
|
//When user has got access to Agenda but does not have their own calendar, goes to Agenda
|
2023-10-09 14:15:21 +01:00
|
|
|
if (this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0) {
|
2022-12-26 17:04:20 +01:00
|
|
|
this.router.navigate(['/home/agenda']);
|
|
|
|
|
}
|
2023-10-09 14:15:21 +01:00
|
|
|
else {
|
2022-12-26 17:04:20 +01:00
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//If user has access permission to both Chat and Action, goes to Chat by default.
|
2023-10-09 14:15:21 +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-12-26 17:04:20 +01:00
|
|
|
this.router.navigate(['/home/chat']);
|
|
|
|
|
}
|
2023-10-09 14:15:21 +01:00
|
|
|
else if (this.p.userPermission(this.p.permissionList.Actions.access)) {
|
2022-12-26 17:04:20 +01:00
|
|
|
this.router.navigate(['/home/publications']);
|
|
|
|
|
}
|
2021-09-02 12:17:14 +01:00
|
|
|
}
|
2021-09-02 13:22:10 +01:00
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-08 08:58:13 +01:00
|
|
|
usernameAsDomain(substring, mainString) {
|
|
|
|
|
return mainString.includes(substring);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 14:40:29 +01:00
|
|
|
}
|