diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index cb879693d..f6ed7fa9b 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -1,6 +1,7 @@ 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 { LocalstoreService } from '../store/localstore.service'; import { SessionStore } from '../store/session.service'; @@ -10,7 +11,8 @@ import { SessionStore } from '../store/session.service'; export class AuthGuard implements CanActivate { constructor( private router:Router, - private localstoreService: LocalstoreService + private localstoreService: LocalstoreService, + private authService: AuthService, ){} canActivate( @@ -27,6 +29,7 @@ export class AuthGuard implements CanActivate { this.router.navigate(['/']); return false } else { + this.authService.loginChat(SessionStore.user) return true } } diff --git a/src/app/modals/set-room-owner/set-room-owner.page.ts b/src/app/modals/set-room-owner/set-room-owner.page.ts index ac9939bf2..89d728161 100644 --- a/src/app/modals/set-room-owner/set-room-owner.page.ts +++ b/src/app/modals/set-room-owner/set-room-owner.page.ts @@ -84,7 +84,6 @@ export class SetRoomOwnerPage implements OnInit { } this.chatService.addGroupOwner(body).subscribe((res)=>{ - alert('here'); console.log(res); this.close(); this.toastService._successMessage('Operação realizada com sucesso'); diff --git a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts index 87b8de6dd..08d599ff8 100644 --- a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts +++ b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts @@ -261,7 +261,6 @@ export class BookMeetingModalPage implements OnInit { } if(this.task.FsId == '8') { - alert('Chegou') const loader = this.toastService.loading() try { switch (this.loggeduser.Profile) { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 7373f3c72..46be42992 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -100,7 +100,6 @@ export class LoginPage implements OnInit { // login to API successfully if (attempt) { - if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); await this.authService.loginChat(this.userattempt); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 6620a316c..be564c886 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -107,12 +107,17 @@ export class AuthService { } } - //Login to rocketChat server - async loginChat(user: UserForm) { - const expireDate = new Date(new Date().getTime() + 60*1000); + //Login to rocketChat server2 + //user: UserForm + async loginChat(user: any) { + + const expirationMinutes = 60; + let date = new Date().getTime(); + let expirationDate = new Date(new Date().getTime() + expirationMinutes*60*1000); + let postData = { - "user": user.username, - "password": user.password, + "user": user.RochetChatUser, + "password": user.Password, } let responseChat = await this.httpService.post('login', postData).toPromise(); @@ -125,17 +130,19 @@ export class AuthService { this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); this.storageService.store(AuthConnstants.AUTH, responseChat); - - /* this.autologout(10000); */ - - return true; - } else{ console.log('Network error'); this.presentAlert('Network error'); - return false; } + + this.autoLoginChat(expirationDate.getTime() - date, user); + } + + async autoLoginChat(expirationDate:number, user:any){ + setTimeout(()=>{ + this.loginChat(user); + }, expirationDate) } private loginToChatWs() { @@ -150,8 +157,8 @@ export class AuthService { }) - this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => { - + this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => { + if(message.hasFile) { if(message.file.type != 'application/webtrix') { const formData = message.temporaryData @@ -163,14 +170,14 @@ export class AuthService { console.log('add picture to chat IMAGE SAVED') message.getFileFromDb() }); - + return true } catch(e) { return false } } else { - try { + try { const res = message.temporaryData let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise(); let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1"); @@ -181,7 +188,7 @@ export class AuthService { } catch(e) { return false } - + } } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 6ea061412..9d3a6268f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -187,12 +187,12 @@ export class WsChatMethodsService { */ private defaultSubtribe(id: any) { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ - console.log('streamRoomMessages', subscription) + //console.log('streamRoomMessages', subscription) }) this.WsChatService.subStreamNotifyRoom(id, 'typing', false) this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{ - console.log('streamNotifyRoomDeleteMessage', subscription); + //console.log('streamNotifyRoomDeleteMessage', subscription); }) } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 593b79276..d4904bf0c 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -657,11 +657,11 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { for (const [key, item] of Object.entries(this.wsMsgQueue)) { if(item.loginRequired == true && this.isLogin == true) { - console.log('run msgQueue ', key) + //console.log('run msgQueue ', key) this.ws.send(item); delete this.wsMsgQueue[key] } else if(item.loginRequired == false) { - console.log('run msgQueue ', key) + //console.log('run msgQueue ', key) this.ws.send(item); delete this.wsMsgQueue[key] } diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index 4ab379fa8..2554b51d6 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -62,7 +62,7 @@ export class FileService { data: base64Data, directory: Directory.Data }); - + } //new method 3 @@ -160,7 +160,7 @@ export class FileService { return new Promise((resolve, reject)=>{ input.onchange = async () => { const file = this.fileLoaderService.getFirstFile(input) - + resolve(file); }; }) diff --git a/src/app/shared/chat/new-group/new-group.page.ts b/src/app/shared/chat/new-group/new-group.page.ts index 9bcc2eddc..75b4f7d37 100644 --- a/src/app/shared/chat/new-group/new-group.page.ts +++ b/src/app/shared/chat/new-group/new-group.page.ts @@ -67,7 +67,6 @@ export class NewGroupPage implements OnInit{ } /* ngOnDestroy(){ - alert('Destroy') this.dataService.set("newGroup", false); this.dataService.set("task", null); this.dataService.set("newGroupName", ''); diff --git a/src/app/store/session.service.ts b/src/app/store/session.service.ts index 3e480e7bc..e1f510138 100644 --- a/src/app/store/session.service.ts +++ b/src/app/store/session.service.ts @@ -12,7 +12,7 @@ class SessionService { // main data private _user = new UserSession() // local storage keyName - private keyName: string; + private keyName: string; constructor() { @@ -73,7 +73,7 @@ class SessionService { return false } return this._user.PIN.length >= 2 - + } reset(user) { @@ -98,4 +98,4 @@ class SessionService { } -export const SessionStore = new SessionService() \ No newline at end of file +export const SessionStore = new SessionService()