diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts index 451d2466e9d2f9b02bf5ee5ae731fb35c4950154..f964fdd844ef4633f2855227ae5dc12b934f8fc7 100755 --- a/src/frontend/app/document/document.component.ts +++ b/src/frontend/app/document/document.component.ts @@ -467,9 +467,9 @@ export class DocumentComponent implements OnInit { if (notesContent) { const storageContent = JSON.parse(notesContent); - this.signaturesService.notesContent = storageContent['note']; - this.signaturesService.signaturesContent = storageContent['sign']; - this.signaturesService.datesContent = storageContent['date']; + this.signaturesService.notesContent = storageContent['note'] !== undefined ? storageContent['note'] : []; + this.signaturesService.signaturesContent = storageContent['sign'] !== undefined ? storageContent['sign'] : []; + this.signaturesService.datesContent = storageContent['date'] !== undefined ? storageContent['date'] : []; } this.signaturesService.currentAction = 0; diff --git a/src/frontend/app/service/actions.service.ts b/src/frontend/app/service/actions.service.ts index c96fe9c433094a53d6d367fc1bf8f52b11ce8f33..ed204e74e1ae7fef4e0de13c4d3355d72407d595 100644 --- a/src/frontend/app/service/actions.service.ts +++ b/src/frontend/app/service/actions.service.ts @@ -1,7 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { LatinisePipe } from 'ngx-pipes'; import { tap, catchError } from 'rxjs/operators'; import { SignaturesContentService } from './signatures.service'; import { NotificationService } from '../service/notification.service'; @@ -16,67 +15,21 @@ export class ActionsService { constructor( public http: HttpClient, public translate: TranslateService, - private latinisePipe: LatinisePipe, public notificationService: NotificationService, public signaturesService: SignaturesContentService, private functionsService: FunctionsService ) { } - sendDocument(note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgSignatures: any[] = null) { + sendDocument(note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgDocElements: any[] = null) { return new Promise(async (resolve) => { - let signatures: any[] = []; + let data: any = {}; + if (this.signaturesService.currentAction > 0) { - if (imgSignatures === null) { - for (let index = 1; index <= this.signaturesService.totalPage; index++) { - if (this.signaturesService.datesContent[index]) { - this.signaturesService.datesContent[index].forEach((date: any) => { - signatures.push( - { - 'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''), - 'width': date.width, - 'positionX': date.positionX, - 'positionY': date.positionY, - 'type': 'SVG', - 'page': index, - } - ); - }); - } - if (this.signaturesService.signaturesContent[index]) { - this.signaturesService.signaturesContent[index].forEach((signature: any) => { - signatures.push( - { - 'encodedImage': signature.encodedSignature, - 'width': signature.width, - 'positionX': signature.positionX, - 'positionY': signature.positionY, - 'type': 'PNG', - 'page': index, - } - ); - }); - } - if (this.signaturesService.notesContent[index]) { - this.signaturesService.notesContent[index].forEach((noteItem: any) => { - signatures.push( - { - 'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''), - 'width': noteItem.width, - 'positionX': noteItem.positionX, - 'positionY': noteItem.positionY, - 'type': 'PNG', - 'page': index, - } - ); - }); - } - } + if (imgDocElements === null) { + data.signatures = this.getElementsFromDoc(); } else { - signatures = imgSignatures; + data.signatures = imgDocElements; } - let data: any = {}; - - data.signatures = signatures; if (eSignature !== null) { data = {...data, ...eSignature }; @@ -125,4 +78,54 @@ export class ActionsService { } }); } + + getElementsFromDoc() { + const signatures: any[] = []; + for (let index = 1; index <= this.signaturesService.totalPage; index++) { + if (this.signaturesService.datesContent[index]) { + this.signaturesService.datesContent[index].forEach((date: any) => { + signatures.push( + { + 'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''), + 'width': date.width, + 'positionX': date.positionX, + 'positionY': date.positionY, + 'type': 'SVG', + 'page': index, + } + ); + }); + } + if (this.signaturesService.signaturesContent[index]) { + this.signaturesService.signaturesContent[index].forEach((signature: any) => { + signatures.push( + { + 'encodedImage': signature.encodedSignature, + 'width': signature.width, + 'positionX': signature.positionX, + 'positionY': signature.positionY, + 'type': 'PNG', + 'page': index, + } + ); + }); + } + if (this.signaturesService.notesContent[index]) { + this.signaturesService.notesContent[index].forEach((noteItem: any) => { + signatures.push( + { + 'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''), + 'width': noteItem.width, + 'positionX': noteItem.positionX, + 'positionY': noteItem.positionY, + 'type': 'PNG', + 'page': index, + } + ); + }); + } + } + + return signatures; + } } diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.html b/src/frontend/app/service/signature-method/signature-method-modal.component.html index c5983026bc03b73e6e713a89c2f62039fb7c54e5..5aaa59004357c7a9f66020a379cb0e756ad666bf 100644 --- a/src/frontend/app/service/signature-method/signature-method-modal.component.html +++ b/src/frontend/app/service/signature-method/signature-method-modal.component.html @@ -1,4 +1,4 @@ <ion-content> <peculiar-fortify-certificates style="height: 100%;width: 100%;" language="fr" [filters]="filters" - (continue)="continueSignature($event)" (cancel)="cancelSign()" hide-footer></peculiar-fortify-certificates> + (continue)="certificateChosen($event)" (cancel)="cancelSign()" hide-footer></peculiar-fortify-certificates> </ion-content> diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.ts b/src/frontend/app/service/signature-method/signature-method-modal.component.ts index 30a90e563f6321a03d9a7f1458c1d12ea2b63e7b..3a568a6375c12281728503426ddae26c5392117b 100644 --- a/src/frontend/app/service/signature-method/signature-method-modal.component.ts +++ b/src/frontend/app/service/signature-method/signature-method-modal.component.ts @@ -54,61 +54,15 @@ export class SignatureMethodModalComponent implements OnInit { ) { } ngOnInit(): void { - this.getSignatures(); + this.signatures = this.actionsService.getElementsFromDoc(); + const signatureModeData = this.authService.signatureRoles.filter((mode: any) => mode.id === this.signatureMode)[0]; if (!this.functionsService.empty(signatureModeData.issuer)) { this.filters.issuerDNMatch = new RegExp(signatureModeData.issuer, 'i'); } } - getSignatures() { - for (let index = 1; index <= this.signaturesService.totalPage; index++) { - if (this.signaturesService.datesContent[index]) { - this.signaturesService.datesContent[index].forEach((date: any) => { - this.signatures.push( - { - 'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''), - 'width': date.width, - 'positionX': date.positionX, - 'positionY': date.positionY, - 'type': 'SVG', - 'page': index, - } - ); - }); - } - if (this.signaturesService.signaturesContent[index]) { - this.signaturesService.signaturesContent[index].forEach((signature: any) => { - this.signatures.push( - { - 'encodedImage': signature.encodedSignature, - 'width': signature.width, - 'positionX': signature.positionX, - 'positionY': signature.positionY, - 'type': 'PNG', - 'page': index, - } - ); - }); - } - if (this.signaturesService.notesContent[index]) { - this.signaturesService.notesContent[index].forEach((noteItem: any) => { - this.signatures.push( - { - 'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''), - 'width': noteItem.width, - 'positionX': noteItem.positionX, - 'positionY': noteItem.positionY, - 'type': 'PNG', - 'page': index, - } - ); - }); - } - } - } - - async continueSignature(certData: any) { + async certificateChosen(certData: any) { this.loadingController.create({ message: this.translate.instant('lang.processing'), spinner: 'dots' @@ -138,6 +92,38 @@ export class SignatureMethodModalComponent implements OnInit { }); } + async sendAndSign() { + let allSignaturesComplete: boolean = false; + let res: any = {}; + while (!allSignaturesComplete) { + let signDocComplete: any = false; + while (signDocComplete === false) { + res = await this.fusionStampAndGenerateSignature(res.tmpUniqueId); + if (res === null) { + return false; + } else if (res !== false) { + signDocComplete = await this.signDocument(res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId); + console.log('signDocComplete', signDocComplete); + if (signDocComplete === true) { + this.signatures.shift(); + allSignaturesComplete = this.signatures.length === 0; + } else { + return false; + } + } else { + return false; + } + } + } + return allSignaturesComplete; + } + + async fusionStampAndGenerateSignature(tmpUniqueId: string = null) { + let res: any = {}; + res = await this.actionsService.sendDocument(null, this.certificate, this.signatureLength, tmpUniqueId, this.signatures); + return res; + } + signDocument(hashDocument: any, eSignatureLength: any, signatureFieldName: any, tmpUniqueId: string) { return new Promise(async (resolve) => { const alg = { @@ -156,6 +142,10 @@ export class SignatureMethodModalComponent implements OnInit { return of(false); } + const note = { + note: this.note + }; + const objEsign = { signatures : this.signatures, certificate: this.certPem, @@ -164,7 +154,10 @@ export class SignatureMethodModalComponent implements OnInit { signatureFieldName: signatureFieldName, tmpUniqueId: tmpUniqueId, }; - this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, objEsign) + + const objToSend = {...note, ...objEsign }; + + this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, objToSend) .pipe( tap(() => { resolve(true); @@ -175,7 +168,7 @@ export class SignatureMethodModalComponent implements OnInit { resolve(false); } else { this.notificationService.handleErrors(err); - resolve(null); + resolve('error'); } return of(false); }) @@ -184,27 +177,6 @@ export class SignatureMethodModalComponent implements OnInit { }); } - async sendAndSign() { - let allSignaturesComplete: boolean = false; - let res: any = {}; - while (!allSignaturesComplete) { - let signDocComplete: any = false; - while (signDocComplete === false) { - res = await this.actionsService.sendDocument(this.note, this.certificate, this.signatureLength, res.tmpUniqueId, this.signatures); - if (res === null) { - return false; - } else if (res !== false) { - signDocComplete = await this.signDocument(res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId); - if (signDocComplete) { - this.signatures.shift(); - allSignaturesComplete = this.signatures.length === 0; - } - } - } - } - return allSignaturesComplete; - } - cancelSign() { this.modalController.dismiss(false); } diff --git a/src/frontend/app/service/signature-method/signature-method.service.ts b/src/frontend/app/service/signature-method/signature-method.service.ts index 6f5dbf31dcff94e0ce5cfdb1c870af6e039e6921..4aa0543b0c1a4a87ee5448cc30dc0b5c0b954af3 100644 --- a/src/frontend/app/service/signature-method/signature-method.service.ts +++ b/src/frontend/app/service/signature-method/signature-method.service.ts @@ -16,7 +16,6 @@ export class SignatureMethodService { ) { } async checkAuthenticationAndLaunchAction(userWorkflow: any, note: any = null) { - console.log(userWorkflow); if (['rgs_2stars', 'rgs_2stars_timestamped', 'inca_card', 'inca_card_eidas'].indexOf(userWorkflow.signatureMode) > -1) { const res = await this.openRgsAuth(note, userWorkflow.signatureMode); return res;