21/03/2024 - 23h30
parent
15f1a24c89
commit
383a17117e
|
@ -1,12 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="19/03/2024 - 17h30">
|
||||
<change afterPath="$PROJECT_DIR$/E_Sign_Document.py" afterDir="false" />
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="20/03/2024 - 22h30">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/E_Sign_Document.py" beforeDir="false" afterPath="$PROJECT_DIR$/E_Sign_Document.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/crm_opportunite.py" beforeDir="false" afterPath="$PROJECT_DIR$/crm_opportunite.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -77,13 +76,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00196" summary="15/01/2024 - 22h">
|
||||
<created>1705352583884</created>
|
||||
<option name="number" value="00196" />
|
||||
<option name="presentableId" value="LOCAL-00196" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1705352583884</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00197" summary="16/01/2024 - 19h">
|
||||
<created>1705426888964</created>
|
||||
<option name="number" value="00197" />
|
||||
|
@ -420,7 +412,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1710866627532</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="245" />
|
||||
<task id="LOCAL-00245" summary="20/03/2024 - 22h30">
|
||||
<created>1710970329202</created>
|
||||
<option name="number" value="00245" />
|
||||
<option name="presentableId" value="LOCAL-00245" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1710970329203</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="246" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -435,7 +434,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="13/02/2024 - 11h" />
|
||||
<MESSAGE value="17/02/2024 - 11h" />
|
||||
<MESSAGE value="18/02/2024 - 14h" />
|
||||
<MESSAGE value="dd" />
|
||||
|
@ -460,6 +458,7 @@
|
|||
<MESSAGE value="11/03/2024 - 15h" />
|
||||
<MESSAGE value="12/03/2024 - 20h30" />
|
||||
<MESSAGE value="19/03/2024 - 17h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="19/03/2024 - 17h30" />
|
||||
<MESSAGE value="20/03/2024 - 22h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="20/03/2024 - 22h30" />
|
||||
</component>
|
||||
</project>
|
|
@ -75,7 +75,7 @@ from email import encoders
|
|||
import hashlib
|
||||
from Crypto.Cipher import PKCS1_OAEP
|
||||
from Crypto.PublicKey import RSA
|
||||
|
||||
import segno
|
||||
|
||||
class SignedMessage:
|
||||
message: bytes = None
|
||||
|
@ -106,7 +106,7 @@ def Create_E_Document(diction):
|
|||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'file_name', 'related_collection', 'related_collection_id',
|
||||
'email_destinataire']
|
||||
'email_destinataire', 'source_document']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -119,7 +119,7 @@ def Create_E_Document(diction):
|
|||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'file_name', 'related_collection', 'related_collection_id',
|
||||
'email_destinataire']
|
||||
'email_destinataire', 'source_document']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -172,18 +172,21 @@ def Create_E_Document(diction):
|
|||
new_diction['statut'] = '0'
|
||||
new_diction['valide'] = '1'
|
||||
new_diction['locked'] = "0"
|
||||
new_diction['secret_key'] = str(secret_key)
|
||||
new_diction['secret_key_open'] = str(secret_key)
|
||||
new_diction['email_destinataire'] = str(diction['email_destinataire'])
|
||||
new_diction['source_document'] = str(diction['source_document'])
|
||||
new_diction['date_update'] = str(datetime.now())
|
||||
new_diction['update_by'] = str(my_partner['_id'])
|
||||
|
||||
val = MYSY_GV.dbname['e_document_signe'].insert_one(new_diction)
|
||||
|
||||
|
||||
if (val is None):
|
||||
mycommon.myprint(
|
||||
" Impossible de créer le E-Document (2) ")
|
||||
return False, " Impossible de créer le E-Document (2) "
|
||||
|
||||
return True, str(val['id'])
|
||||
return True, str(val.inserted_id)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
@ -203,7 +206,7 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'e_doc_id', 'secret_key', 'user_email' ]
|
||||
field_list = ['token', 'e_doc_id', 'secret_key_open', 'user_email' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -215,7 +218,7 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'secret_key', 'user_email' ]
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'secret_key_open', 'user_email' ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -246,12 +249,12 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction):
|
|||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
local_partner_owner_recid = ""
|
||||
|
||||
|
||||
qry = { 'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key':str(diction['secret_key']),
|
||||
'secret_key_open':str(diction['secret_key_open']),
|
||||
'statut':'0'}
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['e_document_signe'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
||||
|
@ -270,12 +273,159 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction):
|
|||
user['document_data'] = decode_data
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
local_partner_owner_recid = str(user['partner_owner_recid'])
|
||||
|
||||
|
||||
if(len(RetObject) <= 0 ):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Aucun E-document trouvé ")
|
||||
return False, " Aucun E-document trouvé "
|
||||
|
||||
"""
|
||||
Un document a été trouvé, a présent il faut
|
||||
1 - Créer la clé de signature
|
||||
2 - Envoyer par email la clé de signature
|
||||
|
||||
"""
|
||||
|
||||
secret_key_for_sign = secrets.token_urlsafe(5)
|
||||
|
||||
|
||||
update_data = {}
|
||||
update_data['secret_key_signature'] = secret_key_for_sign
|
||||
update_data['date_update'] = str(datetime.now())
|
||||
update_data['update_by'] = str(diction['user_email'])
|
||||
|
||||
ret_val2 = MYSY_GV.dbname['e_document_signe'].find_one_and_update(qry,
|
||||
{"$set": update_data},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val2 is None or "_id" not in ret_val2.keys()):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Impossible d'initialiser le processus de signature ")
|
||||
return False, " Impossible d'initialiser le processus de signature "
|
||||
|
||||
"""
|
||||
On envoie la clé de validation de la signature par email
|
||||
"""
|
||||
"""
|
||||
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
||||
"""
|
||||
partner_own_smtp_value = "0"
|
||||
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'partner_smtp',
|
||||
'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
||||
partner_own_smtp_value = partner_own_smtp['config_value']
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_user_pwd',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_server',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_user',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_count_from_name',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_count_port',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||||
else:
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
html = """\
|
||||
<html>
|
||||
<body>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">LOGO</nav>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">SIGNATURE ELECTRONIQUE</nav>
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Bonjour
|
||||
|
||||
</div>
|
||||
<div >
|
||||
Vous venez de lancer une procedure de signature digitale. Voici le code de validation : <br/>
|
||||
|
||||
""" + secret_key_for_sign + """<br>
|
||||
|
||||
</p>
|
||||
Cordialement.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
||||
# sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
html_mime = MIMEText(html, 'html')
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Signature electronique : Clé de signature"
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(diction['user_email'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||||
|
||||
else:
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Signature electronique : Clé de signature"
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(diction['user_email'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
smtpserver.close()
|
||||
print(" Email envoyé " + str(val))
|
||||
|
||||
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
|
@ -307,7 +457,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'e_doc_id', 'secret_key', 'email_destinataire', 'user_ip' ]
|
||||
field_list = ['token', 'e_doc_id', 'secret_key_signature', 'email_destinataire', 'user_ip' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -319,7 +469,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'secret_key', 'email_destinataire' ]
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'secret_key_signature', 'email_destinataire' ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -354,7 +504,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
# Verifier la validité du document
|
||||
qry = { 'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key':str(diction['secret_key']),
|
||||
'secret_key_signature':str(diction['secret_key_signature']),
|
||||
}
|
||||
|
||||
|
||||
|
@ -365,7 +515,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
return False, " L'idientifiant du E-Document est invalide "
|
||||
|
||||
e_document_data = MYSY_GV.dbname['e_document_signe'].find_one(qry)
|
||||
|
||||
local_signature_digitale = ""
|
||||
if ("email_destinataire" in e_document_data.keys() and e_document_data['email_destinataire']):
|
||||
list_email = str(e_document_data['email_destinataire']).replace(",", ";")
|
||||
tab_list_email = list_email.split(";")
|
||||
|
@ -406,7 +556,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
str(inspect.stack()[0][3]) + " L'intégrité du document signé n'est pas valide ")
|
||||
return False, " Impossible de signer le document(3) "
|
||||
|
||||
|
||||
local_signature_digitale = msg.digitalsignature
|
||||
"""
|
||||
Apresent que le message est signé, on va mettre à jour le doc
|
||||
"""
|
||||
|
@ -421,7 +571,7 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
|
||||
qry_key = {'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key': str(diction['secret_key']),
|
||||
'secret_key_signature': str(diction['secret_key_signature']),
|
||||
'email_destinataire': str(diction['email_destinataire'])}
|
||||
|
||||
|
||||
|
@ -441,6 +591,231 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
str(inspect.stack()[0][3]) + " L'idientifiant du E-Document est invalide ")
|
||||
return False, " L'idientifiant du E-Document est invalide "
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Vu que tout est ok, on va créer le fichier pdf definif.
|
||||
on va utiliser le contenu du champ "source_document" au quel on a ajouté un tag de la signature
|
||||
"""
|
||||
|
||||
qry_key = {'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key_signature': str(diction['secret_key_signature']),
|
||||
'email_destinataire': str(diction['email_destinataire'])}
|
||||
|
||||
e_document_date_2 = MYSY_GV.dbname['e_document_signe'].find_one(qry_key)
|
||||
|
||||
local_partner_owner_recid = e_document_date_2['partner_owner_recid']
|
||||
|
||||
local_signature_digitale = decrypt.decrypt(e_document_date_2['signature_digitale'])
|
||||
|
||||
local_url_securite = MYSY_GV.CLIENT_URL_BASE+"E_Document/"+str(e_document_date_2['_id'])+"/"+str(e_document_date_2['partner_owner_recid'])+"/"+str(e_document_date_2['secret_key_signature'])
|
||||
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
||||
qr_code_img_file = str(MYSY_GV.TEMPORARY_DIRECTORY_V2) + "qr_code_" + str(ts) + ".png"
|
||||
|
||||
qrcode = segno.make_qr(str(local_url_securite))
|
||||
qrcode.save(
|
||||
qr_code_img_file,
|
||||
scale=5,
|
||||
border=10,
|
||||
)
|
||||
|
||||
qr_code_converted_string = ""
|
||||
with open(qr_code_img_file, "rb") as image2string:
|
||||
qr_code_converted_string = base64.b64encode(image2string.read())
|
||||
|
||||
print(" ### qr_code_converted_string = ", qr_code_converted_string)
|
||||
img_qr_code = "data:image/png;base64," + str(qr_code_converted_string)
|
||||
|
||||
print(" ### img_qr_code = ", img_qr_code)
|
||||
|
||||
body = {
|
||||
"params": {"mysy_signature_digitale":str(local_signature_digitale),
|
||||
'mysy_url_securite':local_url_securite,
|
||||
'mysy_qrcode_securite':img_qr_code},
|
||||
}
|
||||
contenu_doc_Template = jinja2.Template(str(e_document_data['source_document']))
|
||||
|
||||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||||
|
||||
orig_file_name = "Convention_Signe_" + str(ts) + ".pdf"
|
||||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||||
|
||||
# open output file for writing (truncated binary)
|
||||
resultFile = open(outputFilename, "w+b")
|
||||
|
||||
# convert HTML to PDF
|
||||
pisaStatus = pisa.CreatePDF(
|
||||
src=sourceHtml, # the HTML to convert
|
||||
dest=resultFile) # file handle to receive result
|
||||
|
||||
# close output file
|
||||
resultFile.close()
|
||||
|
||||
final_encoded_pdf_to_string = ""
|
||||
with open(outputFilename, "rb") as f:
|
||||
final_encoded_pdf_to_string = base64.b64encode(f.read())
|
||||
|
||||
qry_key = {'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key_signature': str(diction['secret_key_signature']),
|
||||
'email_destinataire': str(diction['email_destinataire'])}
|
||||
|
||||
new_data = {}
|
||||
new_data['document_data_signed'] = final_encoded_pdf_to_string
|
||||
result = MYSY_GV.dbname['e_document_signe'].find_one_and_update(
|
||||
qry_key,
|
||||
{"$set": new_data},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
if ("_id" not in result.keys()):
|
||||
mycommon.myprint(
|
||||
" Impossible de signer le document (2) ")
|
||||
return False, " Impossible de signer le document (2) "
|
||||
|
||||
|
||||
"""
|
||||
On envoie le mail avec le document signé
|
||||
"""
|
||||
# Traitement de l'eventuel fichier joint
|
||||
tab_files_to_attache_to_mail = []
|
||||
|
||||
# Attachement du fichier joint
|
||||
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
||||
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
||||
|
||||
encoders.encode_base64(file_to_attache_to_mail)
|
||||
file_to_attache_to_mail.add_header('Content-Disposition',
|
||||
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
||||
|
||||
new_node = {"attached_file": file_to_attache_to_mail}
|
||||
tab_files_to_attache_to_mail.append(new_node)
|
||||
|
||||
html = """\
|
||||
<html>
|
||||
<body>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">LOGO</nav>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">SIGNATURE ELECTRONIQUE</nav>
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Bonjour
|
||||
|
||||
</div>
|
||||
<div >
|
||||
Merci de trouver en pièce jointe le document signé electroniquement
|
||||
|
||||
<br>
|
||||
|
||||
</p>
|
||||
Cordialement.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
"""
|
||||
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
||||
"""
|
||||
partner_own_smtp_value = "0"
|
||||
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'partner_smtp',
|
||||
'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
||||
partner_own_smtp_value = partner_own_smtp['config_value']
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_user_pwd',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_server',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_user',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_count_from_name',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': local_partner_owner_recid,
|
||||
'config_name': 'smtp_count_port',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||||
else:
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
html_mime = MIMEText(html, 'html')
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Votre Document Signé "
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
msg['to'] = str(diction['email_destinataire'])
|
||||
|
||||
# Attacher l'eventuelle pièces jointes
|
||||
for myfile in tab_files_to_attache_to_mail:
|
||||
msg.attach(myfile['attached_file'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||||
|
||||
else:
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Votre Document Signé "
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = msg['to'] = str(diction['email_destinataire'])
|
||||
|
||||
for myfile in tab_files_to_attache_to_mail:
|
||||
msg.attach(myfile['attached_file'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
smtpserver.close()
|
||||
print(" Email envoyé " + str(val))
|
||||
|
||||
return True, " Le document a été correction signé. Vous allez recevoir le document par email"
|
||||
|
||||
except Exception as e:
|
||||
|
@ -448,3 +823,310 @@ def Create_E_Signature_For_E_Document(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de signer le document "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction fait une demande de signature d'un document
|
||||
"""
|
||||
def Sent_E_Document_Signature_Request(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'e_doc_id', 'user_email', ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'user_email', ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
"""
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
"""
|
||||
|
||||
if( mycommon.isEmailValide(str(diction['user_email'])) is False ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + str(diction['user_email']) + "' n'est pas un email valide ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
qry = { 'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'statut':'0'}
|
||||
|
||||
is_e_document_valide = "0"
|
||||
e_document_open_code = ""
|
||||
e_document_data = {}
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['e_document_signe'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
||||
if ("email_destinataire" in New_retVal.keys() and New_retVal['email_destinataire']):
|
||||
list_email = str(New_retVal['email_destinataire']).replace(",", ";")
|
||||
tab_list_email = list_email.split(";")
|
||||
if( diction['user_email'] in tab_list_email ):
|
||||
is_e_document_valide = "1"
|
||||
e_document_data = New_retVal
|
||||
e_document_open_code = New_retVal['secret_key_open']
|
||||
|
||||
if( is_e_document_valide == "0" ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'adresse email du destinataire n'est pas autorisée ")
|
||||
return False, " L'adresse email du destinataire n'est pas autorisée "
|
||||
|
||||
|
||||
"""
|
||||
Si le document est valide, alors on envoie la demande de signture
|
||||
"""
|
||||
url_signature = MYSY_GV.CLIENT_URL_BASE+"E_Signature/"+str(e_document_data['_id'])
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
||||
"""
|
||||
partner_own_smtp_value = "0"
|
||||
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'partner_smtp',
|
||||
'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
||||
partner_own_smtp_value = partner_own_smtp['config_value']
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'smtp_user_pwd',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'smtp_server',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'smtp_user',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'smtp_count_from_name',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(e_document_data['partner_owner_recid']),
|
||||
'config_name': 'smtp_count_port',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||||
else:
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
html = """\
|
||||
<html>
|
||||
<body>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">LOGO</nav>
|
||||
<br />
|
||||
<div style="text-align: center;">
|
||||
<nav style="text-align: center; font-weight: bold;">SIGNATURE ELECTRONIQUE</nav>
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Bonjour
|
||||
|
||||
</div>
|
||||
<div >
|
||||
Cliquez sur le lien ci-dessous pour signer electroniquement le document : <br/>
|
||||
|
||||
""" + url_signature + """<br>
|
||||
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Le code d'ouverture du document est : """+ str(e_document_open_code) +"""
|
||||
</p>
|
||||
Cordialement.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
#contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
||||
#sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
html_mime = MIMEText(html, 'html')
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Signature electronique document"
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(diction['user_email'])
|
||||
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||||
|
||||
else:
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Signature electronique document"
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(diction['user_email'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
smtpserver.close()
|
||||
print(" Email envoyé " + str(val))
|
||||
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer le document électronique "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet d'afficher une document pdf signé et validé
|
||||
ex : quand on scan le qr code sur le document pdf
|
||||
"""
|
||||
"""
|
||||
Recuperation document à signer, sans connexion token
|
||||
"""
|
||||
|
||||
|
||||
def Get_Given_E_Document_Signed_No_Token(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'e_doc_id', 'secret_key_signature', 'partner_owner_recid']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'e_doc_id', 'secret_key_signature', 'partner_owner_recid']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
"""
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
"""
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
local_partner_owner_recid = ""
|
||||
|
||||
qry = {'valide': '1', 'locked': '0',
|
||||
'_id': ObjectId(str(diction['e_doc_id'])),
|
||||
'secret_key_signature': str(diction['secret_key_signature']),
|
||||
'statut': '1',
|
||||
'partner_owner_recid':str(diction['partner_owner_recid']),}
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['e_document_signe'].find(qry, {'_id':1, 'document_data_signed':1}).sort([("_id", pymongo.DESCENDING), ]):
|
||||
user = New_retVal
|
||||
user['id'] = str(val_tmp)
|
||||
if ("signature_digitale" in New_retVal.keys()):
|
||||
del New_retVal['signature_digitale']
|
||||
|
||||
if ("signature_digitale" in New_retVal.keys()):
|
||||
del New_retVal['signature_digitale']
|
||||
|
||||
val_tmp = val_tmp + 1
|
||||
decode_data = user['document_data_signed'].decode()
|
||||
user['document_data_signed'] = decode_data
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
|
||||
if (len(RetObject) <= 0):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Aucun E-document trouvé ")
|
||||
return False, " Aucun E-document trouvé "
|
||||
|
||||
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer le document électronique "
|
||||
|
|
|
@ -9714,10 +9714,17 @@ def Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files_name_full_pat
|
|||
"""
|
||||
1 - Creation du PDF
|
||||
"""
|
||||
|
||||
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
||||
|
||||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
new_model_courrier_with_code_tag = str(sourceHtml) + " <br/> <div> Code Sécurité = {{ params.mysy_signature_digitale }} </div> \
|
||||
<br/> <div> url Sécurité = {{ params.mysy_url_securite }} </div> " \
|
||||
" <br/> qr code : <p> <img class='profil_img' src='{{ params.mysy_url_securite }}'>QR_CODE <br> yyyyy</p> "
|
||||
|
||||
|
||||
|
||||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||||
|
@ -9768,7 +9775,7 @@ def Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files_name_full_pat
|
|||
new_e_document_diction['file_name'] = outputFilename
|
||||
toaddrs = ", ".join(tab_emails_destinataire)
|
||||
new_e_document_diction['email_destinataire'] = str(toaddrs)
|
||||
#new_e_document_diction['email_destinataire'] = "cbalde@mysy-training.com"
|
||||
new_e_document_diction['source_document'] = new_model_courrier_with_code_tag
|
||||
|
||||
new_e_document_diction['related_collection'] = ""
|
||||
new_e_document_diction['related_collection_id'] = ""
|
||||
|
@ -9777,6 +9784,23 @@ def Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files_name_full_pat
|
|||
if(local_status_e_doc is False ):
|
||||
return local_status_e_doc, local_retval_e_doc
|
||||
|
||||
"""
|
||||
Apres la creation du document electronique, on envoie la demande de validation
|
||||
/!\ on envoie le mail à chaque destinataire
|
||||
"""
|
||||
|
||||
for email in tab_emails_destinataire :
|
||||
print(" ### traitement du mail : ", email)
|
||||
new_send_e_document_diction = {}
|
||||
new_send_e_document_diction['token'] = diction['token']
|
||||
new_send_e_document_diction['e_doc_id'] = str(local_retval_e_doc)
|
||||
new_send_e_document_diction['user_email'] = str(email)
|
||||
|
||||
|
||||
local_status_send_e_doc, local_send_retval_e_doc = E_Sign_Document.Sent_E_Document_Signature_Request(new_send_e_document_diction)
|
||||
if( local_status_send_e_doc is False ):
|
||||
return local_status_send_e_doc, local_send_retval_e_doc
|
||||
|
||||
|
||||
else:
|
||||
# Il s'agit d'une simple email
|
||||
|
|
4336
Log/log_file.log
4336
Log/log_file.log
File diff suppressed because one or more lines are too long
12
main.py
12
main.py
|
@ -7986,8 +7986,18 @@ def Create_E_Document():
|
|||
|
||||
|
||||
"""
|
||||
API Pour recuperer un documen électronique
|
||||
API Pour recuperer un documen électronique deja signé. c'est a dire pour un controle d'une tierce partie
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Given_E_Document_Signed_No_Token/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Given_E_Document_Signed_No_Token():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Given_E_Document_Signed_No_Token payload = ",payload)
|
||||
status, retval = E_Sign_Document.Get_Given_E_Document_Signed_No_Token(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour ajouter un document electronique à signer
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue