From 14a041a8aa6e695a0e061bf1022bd6a62de07986 Mon Sep 17 00:00:00 2001 From: merelendor Date: Tue, 16 May 2023 00:22:05 +0300 Subject: [PATCH] fix for digital sign - select only valid certificate for client org and only valid head person --- .../forms/DigitalCertificates.js | 54 +++++++++++++++++-- .../forms/Form_8_Signing/index.js | 9 ++-- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/components/questionnaire/forms/DigitalCertificates.js b/components/questionnaire/forms/DigitalCertificates.js index 160dea4..8083c05 100644 --- a/components/questionnaire/forms/DigitalCertificates.js +++ b/components/questionnaire/forms/DigitalCertificates.js @@ -29,6 +29,8 @@ export default class DigitalCertificates extends React.Component async componentDidMount() { + const { company, main, head_person } = this.props; + //console.log({ company, main }); //console.log("DC", "CDM"); const { CryptoPro } = await import('ruscryptojs'); @@ -52,15 +54,59 @@ export default class DigitalCertificates extends React.Component this.cryptopro.certificateInfo(certificate.id) .then((cert) => { - if(cert.Subject['INNLE'] !== undefined && cert.Subject['INNLE'] !== null && cert.Subject['INNLE'] !== "") + //console.log({ cert }); + if(cert.IsValid) { - if(cert.IsValid) + if(cert.Subject['OGRNIP'] !== undefined && cert.Subject['OGRNIP'] !== null && cert.Subject['OGRNIP'] !== "") { - callback(null, [ { id: certificate.id, fields: cert.Subject, valid_to_date: moment(cert.ValidToDate).format("DD.MM.YYYY") } ]); + if(cert.Subject['INN'] !== undefined && cert.Subject['INN'] !== null && cert.Subject['INN'] !== "") + { + if(company.inn === cert.Subject['INN']) + { + callback(null, [ { id: certificate.id, fields: cert.Subject, valid_to_date: moment(cert.ValidToDate).format("DD.MM.YYYY") } ]); + } + else + { + callback(null, []); + } + } + else + { + callback(null, []); + } } else { - callback(null, []); + if(cert.Subject['INNLE'] !== undefined && cert.Subject['INNLE'] !== null && cert.Subject['INNLE'] !== "") + { + let owner_valid = true; + const fields = [ "lastname", "firstname", "middlename", ]; + const cert_owner = `${ cert.Subject['SN']} ${ cert.Subject['G']}`.toUpperCase(); + + for(let i in fields) + { + if(head_person[fields[i]] !== null && head_person[fields[i]] !== "") + { + if(cert_owner.indexOf(head_person[fields[i]].toUpperCase()) < 0) + { + owner_valid = false; + } + } + } + + if(owner_valid) + { + callback(null, [ { id: certificate.id, fields: cert.Subject, valid_to_date: moment(cert.ValidToDate).format("DD.MM.YYYY") } ]); + } + else + { + callback(null, []); + } + } + else + { + callback(null, []); + } } } else diff --git a/components/questionnaire/forms/Form_8_Signing/index.js b/components/questionnaire/forms/Form_8_Signing/index.js index 3726a81..d5b10e8 100644 --- a/components/questionnaire/forms/Form_8_Signing/index.js +++ b/components/questionnaire/forms/Form_8_Signing/index.js @@ -26,6 +26,7 @@ class Form_8_Signing extends QuestionnaireForm this.state = { loading: true, main: {}, + head_person: {}, signatory_person: {}, sign_digital: true, address: "", @@ -45,6 +46,7 @@ class Form_8_Signing extends QuestionnaireForm main: nextProps.questionnaire.main, signatory_person: nextProps.questionnaire.signatory_person, sign: nextProps.questionnaire.sign, + head_person: nextProps.questionnaire.head_person, company: nextProps.company, }; } @@ -59,7 +61,8 @@ class Form_8_Signing extends QuestionnaireForm //console.log("Form_8_Signing", "CDM", { state: this.state }); - const { main, signatory_person } = this.state; + const { main, head_person, signatory_person } = this.state; + const update = { filename: `${ main.inn }_questionnaire_${ moment().format("DDMMYYYY_HHmmss") }.pdf` }; let digital = true; @@ -142,7 +145,7 @@ class Form_8_Signing extends QuestionnaireForm render() { - const { loading, filename, sign_digital, sign, mobile, company, main, downloading, error, digital_disabled } = this.state; + const { loading, filename, sign_digital, sign, head_person, mobile, company, main, downloading, error, digital_disabled } = this.state; //console.log({ sign }); @@ -202,7 +205,7 @@ class Form_8_Signing extends QuestionnaireForm ) : ( - + ) }