16/03/23 - 17h45
parent
e07d56f3fe
commit
3591ab90bc
|
@ -1,14 +1,16 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="28/02/23 - 17h45">
|
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="06/03/23 - 17h45">
|
||||||
|
<change afterPath="$PROJECT_DIR$/lms_chamilo/local_import.py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/tools_cherif/__init__.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.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$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/business_prices.py" beforeDir="false" afterPath="$PROJECT_DIR$/business_prices.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/data_indexees.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data_indexees.csv" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/ela_output_test_file_pandas_2.txt" beforeDir="false" afterPath="$PROJECT_DIR$/ela_output_test_file_pandas_2.txt" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -340,7 +342,14 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1677602770952</updated>
|
<updated>1677602770952</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="39" />
|
<task id="LOCAL-00039" summary="06/03/23 - 17h45">
|
||||||
|
<created>1678074797958</created>
|
||||||
|
<option name="number" value="00039" />
|
||||||
|
<option name="presentableId" value="LOCAL-00039" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1678074797958</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="40" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
@ -355,7 +364,6 @@
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="27/12/2022 - 11h00" />
|
|
||||||
<MESSAGE value="27/12/2022 - 16h00" />
|
<MESSAGE value="27/12/2022 - 16h00" />
|
||||||
<MESSAGE value="09/01/22 à 11h" />
|
<MESSAGE value="09/01/22 à 11h" />
|
||||||
<MESSAGE value="13/01/22 à 20h" />
|
<MESSAGE value="13/01/22 à 20h" />
|
||||||
|
@ -380,7 +388,8 @@
|
||||||
<MESSAGE value="22/02/23 20h" />
|
<MESSAGE value="22/02/23 20h" />
|
||||||
<MESSAGE value="24/02/23 - 23h23" />
|
<MESSAGE value="24/02/23 - 23h23" />
|
||||||
<MESSAGE value="28/02/23 - 17h45" />
|
<MESSAGE value="28/02/23 - 17h45" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="28/02/23 - 17h45" />
|
<MESSAGE value="06/03/23 - 17h45" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="06/03/23 - 17h45" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
|
|
@ -299,6 +299,35 @@ CLASS_ZONE_DESCRIP_LIMIT = 1000
|
||||||
CLASS_ZONE_OBJECTIF_LIMIT = 1000
|
CLASS_ZONE_OBJECTIF_LIMIT = 1000
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
MariaDB database access
|
||||||
|
"""
|
||||||
|
|
||||||
|
if (MYSY_ENV == "PROD"):
|
||||||
|
MYSY_MARIADB_USER = "mysy_mariadb_user"
|
||||||
|
MYSY_MARIADB_USER_PASS = "fB5z%M)GG&g!n2c"
|
||||||
|
MYSY_MARIADB_HOST = "192.168.1.21"
|
||||||
|
MYSY_MARIADB_PORT = 3306
|
||||||
|
MYSY_LMS_BDD = "mysy_chamilo"
|
||||||
|
|
||||||
|
|
||||||
|
elif (MYSY_ENV == "DEV"):
|
||||||
|
MYSY_MARIADB_USER = "mysy_mariadb_user"
|
||||||
|
MYSY_MARIADB_USER_PASS = "fB5z%M)GG&g!n2c"
|
||||||
|
MYSY_MARIADB_HOST = "192.168.1.21"
|
||||||
|
MYSY_MARIADB_PORT = 3306
|
||||||
|
MYSY_LMS_BDD = "chamilo2"
|
||||||
|
|
||||||
|
elif (MYSY_ENV == "REC"):
|
||||||
|
MYSY_MARIADB_USER = "mysy_mariadb_user"
|
||||||
|
MYSY_MARIADB_USER_PASS = "fB5z%M)GG&g!n2c"
|
||||||
|
MYSY_MARIADB_HOST = "192.168.1.21"
|
||||||
|
MYSY_MARIADB_PORT = 3306
|
||||||
|
MYSY_LMS_BDD = "mysy_chamilo_rec"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Variable pour definir les unité de durée acceptées pour une formation
|
Variable pour definir les unité de durée acceptées pour une formation
|
||||||
|
|
353283
Log/log_file.log
353283
Log/log_file.log
File diff suppressed because one or more lines are too long
30
email_mgt.py
30
email_mgt.py
|
@ -1846,14 +1846,14 @@ def ManualSendInvoiceEmailRIB(diction):
|
||||||
TEMPLATE_FILE = "Template/MySy_Invoice_RIB_tpl.html"
|
TEMPLATE_FILE = "Template/MySy_Invoice_RIB_tpl.html"
|
||||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||||
body = {
|
body = {
|
||||||
"params": {"order_id": "007G",
|
"params": {"order_id": "005G",
|
||||||
"date_order": ": 01/03/2023",
|
"date_order": ": 07/03/2023",
|
||||||
"total_ht": "171",
|
"total_ht": "150",
|
||||||
"tva": "34,2",
|
"tva": "0",
|
||||||
"total_ttc": "205,2",
|
"total_ttc": "150",
|
||||||
"client_name": "CAP SANTE",
|
"client_name": "HIFMI-INSTITUTE",
|
||||||
"client_address": "4 Allée des Jacquiers",
|
"client_address": "50 AV PIERRE ET MARIE CURIE",
|
||||||
"client_zip_ville": "97427 L'Etang Salé",
|
"client_zip_ville": "93700 DRANCY",
|
||||||
"client_pays": "France",
|
"client_pays": "France",
|
||||||
"packs": "PACK GOLD ",
|
"packs": "PACK GOLD ",
|
||||||
"detail_packs": "-- Support téléphonique -- "
|
"detail_packs": "-- Support téléphonique -- "
|
||||||
|
@ -1865,13 +1865,13 @@ def ManualSendInvoiceEmailRIB(diction):
|
||||||
"Envoi de 1000 emails markéting / mois --"
|
"Envoi de 1000 emails markéting / mois --"
|
||||||
"Reporting Dynamique et personnalisé",
|
"Reporting Dynamique et personnalisé",
|
||||||
|
|
||||||
"qty": "2",
|
"qty": "3",
|
||||||
"unit_price": "85.5",
|
"unit_price": "50",
|
||||||
"montant": "171",
|
"montant": "150",
|
||||||
"invoice_id": "FACT_230300026",
|
"invoice_id": "FACT_230300027",
|
||||||
"invoice_date": "01/03/2023",
|
"invoice_date": "07/03/2023",
|
||||||
"due_date": "01/03/2022",
|
"due_date": "07/03/2022",
|
||||||
"orign_order": "Contrat 007G",
|
"orign_order": "Contrat 005G",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceHtml = template.render(params=body["params"])
|
sourceHtml = template.render(params=body["params"])
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import pymongo
|
||||||
|
import zeep
|
||||||
|
from pymongo import MongoClient
|
||||||
|
import json
|
||||||
|
from bson import ObjectId
|
||||||
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
import prj_common as mycommon
|
||||||
|
import secrets
|
||||||
|
import inspect
|
||||||
|
import sys, os
|
||||||
|
import csv
|
||||||
|
import pandas as pd
|
||||||
|
from pymongo import ReturnDocument
|
||||||
|
from math import isnan
|
||||||
|
import GlobalVariable as MYSY_GV
|
||||||
|
import ela_index_bdd_classes as eibdd
|
||||||
|
import email_mgt as email
|
||||||
|
import socket
|
||||||
|
import smtplib
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
# Connexion mariadb sur serveur
|
||||||
|
import mariadb
|
||||||
|
import hashlib
|
||||||
|
import bcrypt
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,533 @@
|
||||||
|
import pymongo
|
||||||
|
import zeep
|
||||||
|
from pymongo import MongoClient
|
||||||
|
import json
|
||||||
|
from bson import ObjectId
|
||||||
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
import prj_common as mycommon
|
||||||
|
import secrets
|
||||||
|
import inspect
|
||||||
|
import sys, os
|
||||||
|
import csv
|
||||||
|
import pandas as pd
|
||||||
|
from pymongo import ReturnDocument
|
||||||
|
from math import isnan
|
||||||
|
import GlobalVariable as MYSY_GV
|
||||||
|
import ela_index_bdd_classes as eibdd
|
||||||
|
import email_mgt as email
|
||||||
|
import socket
|
||||||
|
import smtplib
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
# Connexion mariadb sur serveur
|
||||||
|
import mariadb
|
||||||
|
import hashlib
|
||||||
|
import bcrypt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction créer un utilisateur lms mysy, donc dans chamilo
|
||||||
|
"""
|
||||||
|
def Create_MySy_LMS_User(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
'''
|
||||||
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
||||||
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
||||||
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||||
|
# field_list.
|
||||||
|
'''
|
||||||
|
field_list = ['token', 'lastname', 'firstname', 'email', 'password', 'locked', 'official_code', 'username']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, " Le champ '" + val + "' n'est pas autorisé", False
|
||||||
|
|
||||||
|
'''
|
||||||
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||||
|
On controle que les champs obligatoires sont presents dans la liste
|
||||||
|
'''
|
||||||
|
field_list_obligatoire = ['token', 'lastname', 'firstname', 'email', 'password', 'locked', 'official_code']
|
||||||
|
|
||||||
|
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, " Toutes les informations obligatoire n'ont pas été fournies", False
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, " Impossible de créer le compte LMS", False
|
||||||
|
|
||||||
|
# Recuperation du recid de l'utilisateur
|
||||||
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||||
|
if partner_recid is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token du partenaire")
|
||||||
|
return False, " Impossible de recuperer le token du partenaire", False
|
||||||
|
|
||||||
|
if (len(str(my_token)) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||||
|
return False, " Impossible de créer le compte LMS", False
|
||||||
|
|
||||||
|
lastname = ""
|
||||||
|
if ("lastname" in diction.keys()):
|
||||||
|
if diction['lastname']:
|
||||||
|
lastname = diction['lastname']
|
||||||
|
|
||||||
|
firstname = ""
|
||||||
|
if ("firstname" in diction.keys()):
|
||||||
|
if diction['firstname']:
|
||||||
|
firstname = diction['firstname']
|
||||||
|
|
||||||
|
password = ""
|
||||||
|
if ("password" in diction.keys()):
|
||||||
|
if diction['password']:
|
||||||
|
password = diction['password']
|
||||||
|
|
||||||
|
email = ""
|
||||||
|
if ("email" in diction.keys()):
|
||||||
|
if diction['email']:
|
||||||
|
email = diction['email']
|
||||||
|
|
||||||
|
locked = ""
|
||||||
|
if ("locked" in diction.keys()):
|
||||||
|
if diction['email']:
|
||||||
|
locked = diction['locked']
|
||||||
|
|
||||||
|
official_code = ""
|
||||||
|
if ("official_code" in diction.keys()):
|
||||||
|
if diction['official_code']:
|
||||||
|
official_code = diction['official_code']
|
||||||
|
|
||||||
|
username = ""
|
||||||
|
if ("username" in diction.keys()):
|
||||||
|
if diction['username']:
|
||||||
|
username = diction['username']
|
||||||
|
|
||||||
|
registration_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
|
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object':'lms_user_id', 'valide':'1'})
|
||||||
|
|
||||||
|
|
||||||
|
mypasswd = password.encode('UTF-8')
|
||||||
|
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
|
||||||
|
|
||||||
|
|
||||||
|
if (retval is None or "current_val" not in retval.keys()):
|
||||||
|
mycommon.myprint(" Impossible de recuperer la sequence 'mysy_sequence' ")
|
||||||
|
return False, "Impossible de recuperer la sequence 'mysy_sequence'",False
|
||||||
|
|
||||||
|
new_lms_user_id = str(retval['prefixe'])+str(retval['current_val'])
|
||||||
|
local_status, local_val = mycommon.IsInt(new_lms_user_id)
|
||||||
|
if( local_status is False):
|
||||||
|
mycommon.myprint(" Impossible de generer l'ID du user LMS. La valeur actuelle est ", new_lms_user_id)
|
||||||
|
return False, " Impossible de generer l'ID du user LMS", False
|
||||||
|
|
||||||
|
current_seq_value = str(retval['current_val'])
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
"""
|
||||||
|
# retrieving information
|
||||||
|
cur.execute("SELECT username, email_canonical FROM user WHERE id=?", (2,))
|
||||||
|
|
||||||
|
for username, email_canonical in cur:
|
||||||
|
print(f"username: {username}, email_canonical : {email_canonical}")
|
||||||
|
"""
|
||||||
|
|
||||||
|
# insert information
|
||||||
|
my_query = "INSERT INTO user SET id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"user_id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"lastname = '"+lastname+"', " \
|
||||||
|
"firstname = '"+firstname+"', " \
|
||||||
|
"username = '"+username+"', " \
|
||||||
|
"salt = '"+str(salt)+"'," \
|
||||||
|
" registration_date = '"+registration_date+"'," \
|
||||||
|
" credentials_expired='0', " \
|
||||||
|
"enabled='1', " \
|
||||||
|
"expired='0', " \
|
||||||
|
"created_at='" + str( registration_date) + "'," \
|
||||||
|
" updated_at='" + str( registration_date) + "', " \
|
||||||
|
" status = '1', " \
|
||||||
|
"password = '"+str(hashed_pwd)+"', " \
|
||||||
|
"locked = '0', " \
|
||||||
|
"username_canonical = '"+username+"', " \
|
||||||
|
" email_canonical = '"+email+"', " \
|
||||||
|
"email = '"+email+"'," \
|
||||||
|
" official_code = '"+official_code+"', " \
|
||||||
|
"creator_id = '1', " \
|
||||||
|
"auth_source = 'platform'," \
|
||||||
|
"roles = 'a:0:{}', " \
|
||||||
|
"language = 'french'," \
|
||||||
|
"active = '1';"
|
||||||
|
|
||||||
|
try:
|
||||||
|
#print(" ### my_query = ", my_query)
|
||||||
|
#cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(my_query)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS "+str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS "+str({e}), False
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
print(f"Last Inserted ID: {cur.lastrowid}")
|
||||||
|
lastrowid = cur.lastrowid
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Crementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
|
||||||
|
|
||||||
|
new_sequence_value = int(current_seq_value)+1
|
||||||
|
|
||||||
|
mydata = {'current_val':new_sequence_value}
|
||||||
|
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'related_mysy_object':'lms_user_id', 'valide':'1'},
|
||||||
|
{"$set": mydata},
|
||||||
|
return_document=ReturnDocument.AFTER,
|
||||||
|
upsert= False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
return True, " Creation du compte LMS OK. l'id = "+str(lastrowid), str(lastrowid)
|
||||||
|
|
||||||
|
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 créer le compte LMS", False
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction permet de mofifier le mot de passe de l'utilisateur
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def Update_Passwd_MySy_LMS_User(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
'''
|
||||||
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
||||||
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
||||||
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||||
|
# field_list.
|
||||||
|
'''
|
||||||
|
field_list = ['token', 'new_password', 'lms_user_id']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, " Le champ '" + val + "' n'est pas autorisé", False
|
||||||
|
|
||||||
|
'''
|
||||||
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||||
|
On controle que les champs obligatoires sont presents dans la liste
|
||||||
|
'''
|
||||||
|
field_list_obligatoire = ['token', 'new_password', 'lms_user_id']
|
||||||
|
|
||||||
|
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, " Toutes les informations obligatoire n'ont pas été fournies", False
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, " Impossible de mettre à jour le compte LMS", False
|
||||||
|
|
||||||
|
# Recuperation du recid de l'utilisateur
|
||||||
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||||
|
if partner_recid is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token du partenaire")
|
||||||
|
return False, " Impossible de recuperer le token du partenaire", False
|
||||||
|
|
||||||
|
if (len(str(my_token)) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||||
|
return False, " Impossible de mettre à jour le compte LMS", False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
newpassword = ""
|
||||||
|
if ("new_password" in diction.keys()):
|
||||||
|
if diction['new_password']:
|
||||||
|
newpassword = diction['new_password']
|
||||||
|
|
||||||
|
|
||||||
|
lms_user_id = ""
|
||||||
|
if ("lms_user_id" in diction.keys()):
|
||||||
|
if diction['lms_user_id']:
|
||||||
|
lms_user_id = diction['lms_user_id']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
mypasswd = newpassword.encode('UTF-8')
|
||||||
|
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
|
||||||
|
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
"""
|
||||||
|
# retrieving information
|
||||||
|
cur.execute("SELECT username, email_canonical FROM user WHERE id=?", (2,))
|
||||||
|
|
||||||
|
for username, email_canonical in cur:
|
||||||
|
print(f"username: {username}, email_canonical : {email_canonical}")
|
||||||
|
"""
|
||||||
|
|
||||||
|
# insert information
|
||||||
|
my_query = "UPDATE user SET salt = '" + str(salt) + "', credentials_expired='0', " \
|
||||||
|
"updated_at='" + str( updated_at) + " ', " \
|
||||||
|
"password = '" + str( hashed_pwd) + "' " \
|
||||||
|
" WHERE " \
|
||||||
|
"id='" + str(lms_user_id) + "' " \
|
||||||
|
"AND user_id='" + str( lms_user_id) + "' AND enabled='1' AND status = '1' AND active = '1' ;"
|
||||||
|
try:
|
||||||
|
print(" ### my_query update = ", my_query)
|
||||||
|
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(my_query)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
#print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS " + str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS " + str({e}), False
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
#print(f"Last Inserted ID: {cur.lastrowid}")
|
||||||
|
lastrowid = cur.lastrowid
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
return True, " Creation du compte LMS OK. l'id modifié est = " + str(lastrowid), str(lastrowid)
|
||||||
|
|
||||||
|
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 créer le compte LMS", False
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction permet de mettre à jour
|
||||||
|
- le pack abonnement et
|
||||||
|
- le nombre max de formations
|
||||||
|
"""
|
||||||
|
def Update_Pack_MySy_LMS_User(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
'''
|
||||||
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
||||||
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
||||||
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||||
|
# field_list.
|
||||||
|
'''
|
||||||
|
field_list = ['token', 'lms_user_id', 'mysy_pack', 'mysy_nb_formation']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, " Le champ '" + val + "' n'est pas autorisé", False
|
||||||
|
|
||||||
|
'''
|
||||||
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||||
|
On controle que les champs obligatoires sont presents dans la liste
|
||||||
|
'''
|
||||||
|
field_list_obligatoire = ['token', 'lms_user_id', 'mysy_pack', 'mysy_nb_formation']
|
||||||
|
|
||||||
|
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, " Toutes les informations obligatoire n'ont pas été fournies", False
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, " Impossible de mettre à jour le compte LMS", False
|
||||||
|
|
||||||
|
# Recuperation du recid de l'utilisateur
|
||||||
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||||
|
if partner_recid is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token du partenaire")
|
||||||
|
return False, " Impossible de recuperer le token du partenaire", False
|
||||||
|
|
||||||
|
if (len(str(my_token)) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||||
|
return False, " Impossible de mettre à jour le compte LMS", False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mysy_pack = ""
|
||||||
|
if ("mysy_pack" in diction.keys()):
|
||||||
|
if diction['mysy_pack']:
|
||||||
|
mysy_pack = diction['mysy_pack']
|
||||||
|
|
||||||
|
|
||||||
|
mysy_nb_formation = ""
|
||||||
|
if ("mysy_nb_formation" in diction.keys()):
|
||||||
|
if diction['mysy_nb_formation']:
|
||||||
|
mysy_nb_formation = diction['mysy_nb_formation']
|
||||||
|
|
||||||
|
|
||||||
|
lms_user_id = ""
|
||||||
|
if ("lms_user_id" in diction.keys()):
|
||||||
|
if diction['lms_user_id']:
|
||||||
|
lms_user_id = diction['lms_user_id']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
""" MISE à JOUR DU mysy_pack """
|
||||||
|
query_get_mysy_pack_id = "select id from extra_field where variable = 'mysy_pack' "
|
||||||
|
print(" ### query_get_mysy_pack_id = ", query_get_mysy_pack_id)
|
||||||
|
mysy_pack_id = cur.execute(query_get_mysy_pack_id)
|
||||||
|
|
||||||
|
mysy_pack_id_val = ""
|
||||||
|
for mysy_pack_id in cur:
|
||||||
|
print(f"mysy_pack_id: ", mysy_pack_id[0] )
|
||||||
|
mysy_pack_id_val = mysy_pack_id[0]
|
||||||
|
|
||||||
|
query_2 = "select id from extra_field_values where field_id = '"+str(mysy_pack_id_val)+"' and item_id = '"+str(lms_user_id)+"' "
|
||||||
|
print(" ### query_2 = ", query_2)
|
||||||
|
mysy_pack_id2 = cur.execute(query_2)
|
||||||
|
|
||||||
|
mysy_pack_id_val2 = ""
|
||||||
|
for mysy_pack_id2 in cur:
|
||||||
|
print(f"mysy_pack_id2: ", mysy_pack_id2[0])
|
||||||
|
mysy_pack_id_val2 = mysy_pack_id2[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
query_get_mysy_nb_formation_id = "select id from extra_field where variable = '" + str(mysy_nb_formation) + "' "
|
||||||
|
|
||||||
|
localquery = "update extra_field_values set extra_field_values.value ='"+str(mysy_pack)+"' where id = '"+str(mysy_pack_id_val2)+"' "
|
||||||
|
print(" ### localquery = ", localquery)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(" ### my_query update = ", localquery)
|
||||||
|
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(localquery)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
# print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS " + str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS " + str({e}), False
|
||||||
|
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
""" MISE à JOUR DU mysy_nb_formation """
|
||||||
|
query_get_mysy_pack_id = "select id from extra_field where variable = 'mysy_nb_formation' "
|
||||||
|
print(" ### query_get_mysy_pack_id = ", query_get_mysy_pack_id)
|
||||||
|
mysy_pack_id = cur.execute(query_get_mysy_pack_id)
|
||||||
|
|
||||||
|
mysy_pack_id_val = ""
|
||||||
|
for mysy_pack_id in cur:
|
||||||
|
print(f"mysy_pack_id: ", mysy_pack_id[0])
|
||||||
|
mysy_pack_id_val = mysy_pack_id[0]
|
||||||
|
|
||||||
|
query_2 = "select id from extra_field_values where field_id = '" + str(
|
||||||
|
mysy_pack_id_val) + "' and item_id = '" + str(lms_user_id) + "' "
|
||||||
|
print(" ### query_2 = ", query_2)
|
||||||
|
mysy_pack_id2 = cur.execute(query_2)
|
||||||
|
|
||||||
|
mysy_pack_id_val2 = ""
|
||||||
|
for mysy_pack_id2 in cur:
|
||||||
|
print(f"mysy_pack_id2: ", mysy_pack_id2[0])
|
||||||
|
mysy_pack_id_val2 = mysy_pack_id2[0]
|
||||||
|
|
||||||
|
query_get_mysy_nb_formation_id = "select id from extra_field where variable = '" + str(
|
||||||
|
mysy_nb_formation) + "' "
|
||||||
|
|
||||||
|
localquery = "update extra_field_values set extra_field_values.value ='" + str(
|
||||||
|
mysy_nb_formation) + "' where id = '" + str(mysy_pack_id_val2) + "' "
|
||||||
|
print(" ### localquery = ", localquery)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(" ### my_query update = ", localquery)
|
||||||
|
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(localquery)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
# print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS " + str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS " + str({e}), False
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return True, " Creation du compte LMS OK. l'id modifié est = ", 1
|
||||||
|
|
||||||
|
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 créer le compte LMS", False
|
61
main.py
61
main.py
|
@ -38,6 +38,7 @@ import opco as opco
|
||||||
import Attestation_Certificat as Att_Cert
|
import Attestation_Certificat as Att_Cert
|
||||||
import tools_cherif.tools_cherif as tools_cherif
|
import tools_cherif.tools_cherif as tools_cherif
|
||||||
import business_prices as business_prices
|
import business_prices as business_prices
|
||||||
|
import lms_chamilo.mysy_lms as mysy_lms
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||||
|
@ -2344,6 +2345,66 @@ def dirty():
|
||||||
print(" ### dirty : payload = ",payload)
|
print(" ### dirty : payload = ",payload)
|
||||||
localStatus, message= tools_cherif.dirty()
|
localStatus, message= tools_cherif.dirty()
|
||||||
return jsonify(status=localStatus, message=message )
|
return jsonify(status=localStatus, message=message )
|
||||||
|
"""
|
||||||
|
Cette API test SOAP Mysy
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/mysysoap/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def mysysoap():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### dirty : payload = ",payload)
|
||||||
|
localStatus, message= tools_cherif.mysysoap()
|
||||||
|
return jsonify(status=localStatus, message=message )
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/myclass/api/mysylmsdb/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def mysylmsdb():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### mysylmsdb : payload = ",payload)
|
||||||
|
localStatus, message= tools_cherif.mysylmsdb()
|
||||||
|
return jsonify(status=localStatus, message=message )
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API créer un user LMS Mysy, c'est a dire un user chamilo
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Create_MySy_LMS_User/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Create_MySy_LMS_User():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Create_MySy_LMS_User : payload = ",payload)
|
||||||
|
localStatus, message, lms_user_id = mysy_lms.Create_MySy_LMS_User(payload)
|
||||||
|
return jsonify(status=localStatus, message=message , lms_user_id=lms_user_id)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API permettre de mettre à jour le mot de passe dans le LMS
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Update_Passwd_MySy_LMS_User/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Update_Passwd_MySy_LMS_User():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Update_Passwd_MySy_LMS_User : payload = ",payload)
|
||||||
|
localStatus, message, lms_user_id = mysy_lms.Update_Passwd_MySy_LMS_User(payload)
|
||||||
|
return jsonify(status=localStatus, message=message, lms_user_id=lms_user_id)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API met à jour le pack et nombre de formations dans LSM Mysy, c'est a dire chamilo
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Update_Pack_MySy_LMS_User/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Update_Pack_MySy_LMS_User():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Update_Pack_MySy_LMS_User : payload = ",payload)
|
||||||
|
localStatus, message, lms_user_id = mysy_lms.Update_Pack_MySy_LMS_User(payload)
|
||||||
|
return jsonify(status=localStatus, message=message, lms_user_id=lms_user_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/myclass/api/email_validation_mairies/', methods=['POST','GET'])
|
@app.route('/myclass/api/email_validation_mairies/', methods=['POST','GET'])
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
from . import tools_cherif
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
|
import zeep
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
import json
|
import json
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
@ -548,3 +549,241 @@ def dirty():
|
||||||
return False, " Impossible de tester le mail"
|
return False, " Impossible de tester le mail"
|
||||||
|
|
||||||
|
|
||||||
|
# Root de chamilo
|
||||||
|
|
||||||
|
url_root = 'https://online.educetera.org/'
|
||||||
|
|
||||||
|
# Conexión
|
||||||
|
|
||||||
|
from zeep import Client
|
||||||
|
#server = SOAPProxy(url_root+'/main/webservices/soap.php' )
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import urllib.request
|
||||||
|
import hashlib
|
||||||
|
"""
|
||||||
|
url = "https://lms.mysy-training.com/main/webservices/soap.php"
|
||||||
|
|
||||||
|
querystring = {"wsdl":""}
|
||||||
|
|
||||||
|
payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header>\n <UserCredentials xmlns=\"http://microsoft.com/webservices/\">\n <userName>---</userName>\n <password>---</password>\n </UserCredentials>\n </soap:Header>\n <soap:Body>\n <getTrainScheduleJSON xmlns=\"http://microsoft.com/webservices/\">\n <station>NY</station>\n </getTrainScheduleJSON>\n </soap:Body>\n</soap:Envelope>"
|
||||||
|
headers = {
|
||||||
|
'content-type': "text/xml; charset=utf-8",
|
||||||
|
'soapaction': 'https://lms.mysy-training.com/main/webservices/soap.php/WSUser.DisableUser'
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
|
||||||
|
|
||||||
|
print(response.text)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def mysysoap_old():
|
||||||
|
try:
|
||||||
|
|
||||||
|
|
||||||
|
url = "https://lms.mysy-training.com/main/webservices/soap.php"
|
||||||
|
|
||||||
|
querystring = {"wsdl": ""}
|
||||||
|
|
||||||
|
url_root = "http://lms.mysy-training.com/"
|
||||||
|
|
||||||
|
ewurl = "https://lms.mysy-training.com/main/webservices/soap.php"
|
||||||
|
|
||||||
|
full_url = "https://lms.mysy-training.com/main/webservices/testip.php"
|
||||||
|
|
||||||
|
url = "https://lms.mysy-training.com/main/webservices/soap.php/WS.test"
|
||||||
|
|
||||||
|
security_key = 'da6e9548ebb7137b97913ae7589c85c5' # Se encuentra en el archivo main/inc/conf/configuration.php línea 115
|
||||||
|
my_ip = requests.get(full_url).text #
|
||||||
|
|
||||||
|
print(" my is = ", my_ip) # "'#readlines()[0][:-1]
|
||||||
|
|
||||||
|
secret_key = hashlib.sha1(str(my_ip + security_key).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
print(" secret_key = ", secret_key) # "'#readlines()[0][:-1]
|
||||||
|
|
||||||
|
url = 'http://www.dneonline.com/calculator.asmx'
|
||||||
|
xml = """
|
||||||
|
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
|
||||||
|
<soap:Header/>
|
||||||
|
<soap:Body>
|
||||||
|
<tem:Add>
|
||||||
|
<tem:intA>50</tem:intA>
|
||||||
|
<tem:intB>20</tem:intB>
|
||||||
|
</tem:Add>
|
||||||
|
</soap:Body>
|
||||||
|
</soap:Envelope>"""
|
||||||
|
headers = {'content-type': 'application/soap+xml; charset=utf-8'}
|
||||||
|
#r1 = requests.post(url, data=xml, headers=headers)
|
||||||
|
|
||||||
|
url = 'https://lms.mysy-training.com/main/webservices/soap.php'
|
||||||
|
xml = """
|
||||||
|
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
|
||||||
|
<soap:Header/>
|
||||||
|
<soap:Body>
|
||||||
|
<tem:WS.test>
|
||||||
|
|
||||||
|
</tem:WS.test>
|
||||||
|
</soap:Body>
|
||||||
|
</soap:Envelope>"""
|
||||||
|
headers = {'content-type': 'application/soap+xml; charset=utf-8'}
|
||||||
|
r1 = requests.post(url, data=xml, headers=headers)
|
||||||
|
|
||||||
|
print(r1.text)
|
||||||
|
|
||||||
|
return True, "ok"
|
||||||
|
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 tester le mail"
|
||||||
|
|
||||||
|
from zeep import Client, Settings
|
||||||
|
|
||||||
|
|
||||||
|
def mysysoap():
|
||||||
|
try:
|
||||||
|
"""wsdl = "http://www.dneonline.com/calculator.asmx?WSDL"
|
||||||
|
client = Client(wsdl)
|
||||||
|
val = client.service.Add(3, 5)
|
||||||
|
print(val)
|
||||||
|
"""
|
||||||
|
security_key = 'da6e9548ebb7137b97913ae7589c85c5' # Se encuentra en el archivo main/inc/conf/configuration.php línea 115
|
||||||
|
full_url = "https://lms.mysy-training.com/main/webservices/testip.php"
|
||||||
|
my_ip = requests.get(full_url).text #
|
||||||
|
|
||||||
|
print(" my is = ", my_ip) # "'#readlines()[0][:-1]
|
||||||
|
|
||||||
|
secret_key = hashlib.sha1(str(my_ip + security_key).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
print(" secret_key = ", secret_key) # "'#readlines()[0][:-1]
|
||||||
|
|
||||||
|
url = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
|
||||||
|
url="https://lms.mysy-training.com/main/webservices/soap.php?wsdl"
|
||||||
|
headers = {'content-type': 'text/xml'}
|
||||||
|
body = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<SOAP-ENV:Envelope xmlns:ns0="https://lms.mysy-training.com/main/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
|
<SOAP-ENV:Header/>
|
||||||
|
<ns1:Body>
|
||||||
|
<ns0:WSCreateUsers>
|
||||||
|
<secret_key>135b6ca3b7ed29fa787ff011859fd76ec5e1b51c</secret_key>
|
||||||
|
<users>['1504']</users>
|
||||||
|
</ns0:WSCreateUsers>
|
||||||
|
</ns1:Body>
|
||||||
|
</SOAP-ENV:Envelope>"""
|
||||||
|
|
||||||
|
response = requests.post(url, data=body, headers=headers)
|
||||||
|
print(response.content)
|
||||||
|
|
||||||
|
val = "grr"
|
||||||
|
|
||||||
|
return True, "ok val = "+str(response.content)
|
||||||
|
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 tester le mail"
|
||||||
|
|
||||||
|
|
||||||
|
# Connexion mariadb sur serveur
|
||||||
|
import mariadb
|
||||||
|
import hashlib
|
||||||
|
import bcrypt
|
||||||
|
def mysylmsdb():
|
||||||
|
try:
|
||||||
|
|
||||||
|
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object':'lms_user_id', 'valide':'1'})
|
||||||
|
|
||||||
|
print(" ### retval = ",retval)
|
||||||
|
|
||||||
|
mypasswd = 'sekou'.encode('UTF-8')
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
|
||||||
|
|
||||||
|
print(" ## HASHED hashed = ", str(hashed_pwd), " SALT = , ", str(salt))
|
||||||
|
|
||||||
|
|
||||||
|
if (retval is None or "current_val" not in retval.keys()):
|
||||||
|
mycommon.myprint(" Impossible de recuperer la sequence 'mysy_sequence' ")
|
||||||
|
return False, "Impossible de recuperer la sequence 'mysy_sequence'"
|
||||||
|
|
||||||
|
new_lms_user_id = str(retval['prefixe'])+str(retval['current_val'])
|
||||||
|
local_status, local_val = mycommon.IsInt(new_lms_user_id)
|
||||||
|
if( local_status is False):
|
||||||
|
mycommon.myprint(" Impossible de generer l'ID du user LMS. La valeur actuelle est ", new_lms_user_id)
|
||||||
|
return False, " Impossible de generer l'ID du user LMS"
|
||||||
|
|
||||||
|
current_seq_value = str(retval['current_val'])
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
# retrieving information
|
||||||
|
cur.execute("SELECT username, email_canonical FROM user WHERE id=?", (2,))
|
||||||
|
|
||||||
|
for username, email_canonical in cur:
|
||||||
|
print(f"username: {username}, email_canonical : {email_canonical}")
|
||||||
|
|
||||||
|
|
||||||
|
# insert information
|
||||||
|
my_query = "INSERT INTO user SET id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"user_id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"lastname = 'carter', " \
|
||||||
|
"firstname = 'vince_022', " \
|
||||||
|
"username = 'username_1022', " \
|
||||||
|
"salt = '"+str(salt)+"'," \
|
||||||
|
" registration_date = '2022-04-17 15:34:43'," \
|
||||||
|
" credentials_expired='0', " \
|
||||||
|
"enabled='1', " \
|
||||||
|
"expired='0', " \
|
||||||
|
" status = '1', " \
|
||||||
|
"password = '"+str(hashed_pwd)+"', " \
|
||||||
|
"locked = '0', " \
|
||||||
|
"username_canonical = 'username_1022', " \
|
||||||
|
" email_canonical = 'username@mano2.fr', " \
|
||||||
|
"email = 'username@mano2.fr'," \
|
||||||
|
" official_code = 'AAA', " \
|
||||||
|
"creator_id = '1', " \
|
||||||
|
"auth_source = 'platform'," \
|
||||||
|
"roles = 'a:0:{}', " \
|
||||||
|
"language = 'french'," \
|
||||||
|
"active = '1';"
|
||||||
|
|
||||||
|
try:
|
||||||
|
#cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(my_query)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS "+str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS "+str({e})
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
print(f"Last Inserted ID: {cur.lastrowid}")
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Crementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
|
||||||
|
|
||||||
|
new_sequence_value = int(current_seq_value)+1
|
||||||
|
|
||||||
|
mydata = {'current_val':new_sequence_value}
|
||||||
|
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'related_mysy_object':'lms_user_id', 'valide':'1'},
|
||||||
|
{"$set": mydata},
|
||||||
|
return_document=ReturnDocument.AFTER,
|
||||||
|
upsert= False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
return True, "Connexion mariadb OKK"
|
||||||
|
|
||||||
|
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, " Connexion mariadb KOOO"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue