mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
3 dots added to large text
This commit is contained in:
+198
-198
@@ -27,21 +27,21 @@ import { CPSession } from '../store/documentManagement';
|
||||
export class AuthService {
|
||||
userData$ = new BehaviorSubject<any>('');
|
||||
userId$ = new BehaviorSubject<any>('');
|
||||
headers: HttpHeaders = new HttpHeaders();
|
||||
public wsValidatedUserChat:any;
|
||||
headers: HttpHeaders = new HttpHeaders({'rejectUnauthorized': environment.rejectUnauthorized });
|
||||
public wsValidatedUserChat: any;
|
||||
public isWsAuthenticated: boolean = false;
|
||||
opts:any;
|
||||
opts: any;
|
||||
|
||||
tabIsActive = true
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private storageService:StorageService,
|
||||
private storageService: StorageService,
|
||||
public alertController: AlertController,
|
||||
private aesencrypt: AESEncrypt,
|
||||
private RochetChatConnectorService: RochetChatConnectorService,
|
||||
private router: Router,
|
||||
private NfService:NfService,
|
||||
private NfService: NfService,
|
||||
private processesService: ProcessesService,
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private storage: Storage,
|
||||
@@ -51,245 +51,245 @@ export class AuthService {
|
||||
private httpErroHandle: HttpErrorHandle,
|
||||
private errorHandler: ErrorHandler) {
|
||||
|
||||
if (SessionStore.exist) {
|
||||
if(this.p.userPermission(this.p.permissionList.Chat.access) == true ) {
|
||||
this.loginToChatWs()
|
||||
}
|
||||
|
||||
if (SessionStore.exist) {
|
||||
if (this.p.userPermission(this.p.permissionList.Chat.access) == true) {
|
||||
this.loginToChatWs()
|
||||
}
|
||||
|
||||
window.addEventListener('focus', (event) => {
|
||||
if(!this.tabIsActive) {
|
||||
this.tabIsActive = true
|
||||
const data = SessionStore.getDataFromLocalStorage();
|
||||
|
||||
if(!data?.user?.Authorization && SessionStore?.user?.Authorization) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
if(window['all-process-gabinete']) {
|
||||
window['all-process-gabinete']()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('blur', (event) => {
|
||||
this.tabIsActive = false
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async login(user: UserForm, {saveSession = true}): Promise<LoginUserRespose> {
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username ));
|
||||
window.addEventListener('focus', (event) => {
|
||||
if (!this.tabIsActive) {
|
||||
this.tabIsActive = true
|
||||
const data = SessionStore.getDataFromLocalStorage();
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
this.opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
|
||||
|
||||
if(saveSession) {
|
||||
this.SetSession(response, user)
|
||||
if (!data?.user?.Authorization && SessionStore?.user?.Authorization) {
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
this.errorHandler.handleError(error);
|
||||
this.httpErroHandle.loginHttpStatusHandle(error)
|
||||
captureException(error);
|
||||
} finally {
|
||||
|
||||
if (window['all-process-gabinete']) {
|
||||
window['all-process-gabinete']()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('blur', (event) => {
|
||||
this.tabIsActive = false
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async login(user: UserForm, { saveSession = true }): Promise<LoginUserRespose> {
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
this.opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
|
||||
|
||||
if (saveSession) {
|
||||
this.SetSession(response, user)
|
||||
}
|
||||
} catch (error) {
|
||||
this.errorHandler.handleError(error);
|
||||
this.httpErroHandle.loginHttpStatusHandle(error)
|
||||
captureException(error);
|
||||
} finally {
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async loginContenteProduction(user: UserForm, { saveSession = true }): Promise<LoginUserRespose> {
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
this.opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/LoginJwt", '', this.opts).toPromise();
|
||||
console.log('JWT', response)
|
||||
|
||||
if (saveSession) {
|
||||
/* this.SetSession(response, user) */
|
||||
console.log('teste', response);
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
this.httpErroHandle.httpStatusHandle(error)
|
||||
} finally {
|
||||
return response
|
||||
}
|
||||
|
||||
async loginContenteProduction(user: UserForm, {saveSession = true}): Promise<LoginUserRespose> {
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username ));
|
||||
}
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
this.opts = {
|
||||
headers: this.headers,
|
||||
// async UpdateLogin() {}
|
||||
|
||||
SetSession(response: LoginUserRespose, user: UserForm) {
|
||||
const session: UserSession = Object.assign(SessionStore.user, response)
|
||||
|
||||
if (response) {
|
||||
if (session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if (session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
} else if (session.RoleID == 99999872) {
|
||||
session.Profile = 'Consultant'
|
||||
} else if (session.RoleID == 99999886) {
|
||||
session.Profile = 'SGGPR'
|
||||
} else {
|
||||
session.Profile = 'Unknown'
|
||||
}
|
||||
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/LoginJwt", '', this.opts).toPromise();
|
||||
console.log('JWT',response)
|
||||
|
||||
if(saveSession) {
|
||||
/* this.SetSession(response, user) */
|
||||
console.log('teste', response);
|
||||
|
||||
return response
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
this.httpErroHandle.httpStatusHandle(error)
|
||||
} finally {
|
||||
return response
|
||||
}
|
||||
session.Password = user.password
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
SessionStore.reset(session)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// async UpdateLogin() {}
|
||||
this.initialsService.getInitials(session.FullName);
|
||||
}
|
||||
|
||||
SetSession(response: LoginUserRespose, user:UserForm) {
|
||||
const session: UserSession = Object.assign(SessionStore.user, response)
|
||||
loginToChatWs() {
|
||||
setTimeout(() => {
|
||||
|
||||
if (response) {
|
||||
if( session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if(session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
} else if(session.RoleID == 99999872) {
|
||||
session.Profile = 'Consultant'
|
||||
} else if(session.RoleID == 99999886) {
|
||||
session.Profile = 'SGGPR'
|
||||
}else {
|
||||
session.Profile = 'Unknown'
|
||||
}
|
||||
if (SessionStore.user.ChatData?.data) {
|
||||
this.RochetChatConnectorService.connect();
|
||||
this.RochetChatConnectorService.login().then((message: any) => {
|
||||
|
||||
session.Password = user.password
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
SessionStore.reset(session)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.initialsService.getInitials(session.FullName);
|
||||
}
|
||||
|
||||
loginToChatWs() {
|
||||
setTimeout(() => {
|
||||
|
||||
if(SessionStore.user.ChatData?.data) {
|
||||
this.RochetChatConnectorService.connect();
|
||||
this.RochetChatConnectorService.login().then((message: any) => {
|
||||
|
||||
SessionStore.user.RochetChatUserId = message.result.id
|
||||
SessionStore.save()
|
||||
SessionStore.user.RochetChatUserId = message.result.id
|
||||
SessionStore.save()
|
||||
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
window['RochetChatConnectorService'] = this.RochetChatConnectorService
|
||||
setTimeout(() => {
|
||||
this.ChatSystemService.getAllRooms();
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
window['RochetChatConnectorService'] = this.RochetChatConnectorService
|
||||
setTimeout(() => {
|
||||
this.ChatSystemService.getAllRooms();
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
}, 200);
|
||||
}, 200);
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
// console.error(SessionStore.user.ChatData, 'web socket login',error)
|
||||
})
|
||||
}
|
||||
}).catch((error) => {
|
||||
// console.error(SessionStore.user.ChatData, 'web socket login',error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
// before sending a message with a attachment
|
||||
this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => {
|
||||
// before sending a message with a attachment
|
||||
this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
if(message.hasFile) {
|
||||
if(message.file.type != 'application/webtrix') {
|
||||
const formData = message.temporaryData
|
||||
if (message.hasFile) {
|
||||
if (message.file.type != 'application/webtrix') {
|
||||
const formData = message.temporaryData
|
||||
|
||||
try {
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
try {
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
|
||||
message.downloadFileMsg()
|
||||
message.uploadingFile = false
|
||||
message.downloadFileMsg()
|
||||
message.uploadingFile = false
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} catch (e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
return false
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
const res = message.temporaryData
|
||||
} else {
|
||||
try {
|
||||
const res = message.temporaryData
|
||||
|
||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||
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");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
let url_no_options: string = url.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
|
||||
message.uploadingFile = false
|
||||
message.uploadingFile = false
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} catch (e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
//
|
||||
let downloadFile = "";
|
||||
if (message.file.type == "application/img") {
|
||||
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
return true
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
|
||||
message.file = {
|
||||
guid: message.file.guid,
|
||||
image_url: downloadFile,
|
||||
type: message.file.type
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
}, 1)
|
||||
}
|
||||
|
||||
//
|
||||
let downloadFile = "";
|
||||
if (message.file.type == "application/img") {
|
||||
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
autologout(expirationDate: number) {
|
||||
setTimeout(() => {
|
||||
this.logout();
|
||||
}, expirationDate)
|
||||
}
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
return true
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
logout() {
|
||||
|
||||
message.file = {
|
||||
guid: message.file.guid,
|
||||
image_url: downloadFile,
|
||||
type: message.file.type
|
||||
}
|
||||
SessionStore.setInativity(false)
|
||||
SessionStore.setUrlBeforeInactivity(this.router.url);
|
||||
setTimeout(() => {
|
||||
this.router.navigateByUrl('/', { replaceUrl: true });
|
||||
}, 100)
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}, 1)
|
||||
}
|
||||
logoutChat() {
|
||||
}
|
||||
|
||||
autologout(expirationDate:number) {
|
||||
setTimeout(() => {
|
||||
this.logout();
|
||||
}, expirationDate)
|
||||
}
|
||||
async presentAlert(message: string) {
|
||||
const alert = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Mensagem do sistema',
|
||||
message: message,
|
||||
buttons: ['OK']
|
||||
});
|
||||
|
||||
logout() {
|
||||
|
||||
SessionStore.setInativity(false)
|
||||
SessionStore.setUrlBeforeInactivity(this.router.url);
|
||||
setTimeout(() => {
|
||||
this.router.navigateByUrl('/', { replaceUrl: true });
|
||||
}, 100)
|
||||
|
||||
}
|
||||
|
||||
logoutChat() {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
await alert.present();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user