update 28/02/2022 - 10h00
parent
b26e053bd4
commit
0274e09612
3304
Log/log_file.log
3304
Log/log_file.log
File diff suppressed because it is too large
Load Diff
33
main.py
33
main.py
|
@ -483,7 +483,6 @@ def valide_partnair_account(value):
|
|||
|
||||
'''
|
||||
Cette fonction modifie/MAJ un partenaire
|
||||
|
||||
'''
|
||||
@app.route('/myclass/api/update_partner_account/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
|
@ -492,10 +491,40 @@ def update_partner_account():
|
|||
payload = request.form.to_dict()
|
||||
print(" ### payload = ",payload)
|
||||
status, retval = pa.update_partner_account(payload)
|
||||
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Partenair SECURITY : Cette API modifie/MAJ le mail du partenaire
|
||||
'''
|
||||
@app.route('/myclass/api/update_partner_main_mail/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def update_partner_main_mail():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### payload = ",payload)
|
||||
status, retval = pa.update_partner_main_mail(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Partenair SECURITY : Cette API modifie/MAJ le password du partenaire
|
||||
'''
|
||||
@app.route('/myclass/api/update_partner_pwd/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def update_partner_pwd():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### payload = ",payload)
|
||||
status, retval = pa.update_partner_pwd(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Cette fonction recupere les données d'un partenaire
|
||||
|
||||
|
|
215
partners.py
215
partners.py
|
@ -166,13 +166,213 @@ def add_partner_account(diction):
|
|||
|
||||
|
||||
|
||||
'''
|
||||
partner Securité :
|
||||
Cette fonction met à jour l'adresse email du partenaire
|
||||
'''
|
||||
def update_partner_main_mail(diction):
|
||||
try:
|
||||
# Dictionnaire des champs utilisables
|
||||
'''
|
||||
# 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', 'mail', 'new_mail', 'conf_new_mail']
|
||||
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, " Creation partner account : Le champ '" + val + "' n'est pas accepté "
|
||||
|
||||
'''
|
||||
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', 'mail', 'new_mail', 'conf_new_mail']
|
||||
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, " La valeur '" + val + "' n'est pas presente dans liste "
|
||||
|
||||
# Recuperation du recid du partner
|
||||
mydata = {}
|
||||
mytoken = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mytoken = diction['token']
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||
if( partner_recid is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
mymail=""
|
||||
if ("mail" in diction.keys()):
|
||||
if diction['mail']:
|
||||
mymail = diction['mail']
|
||||
|
||||
|
||||
newmail = ""
|
||||
if ("new_mail" in diction.keys()):
|
||||
if diction['new_mail']:
|
||||
newmail = diction['new_mail']
|
||||
mydata['email'] = diction['new_mail']
|
||||
|
||||
|
||||
confnewmail = ""
|
||||
if ("conf_new_mail" in diction.keys()):
|
||||
if diction['conf_new_mail']:
|
||||
confnewmail = diction['conf_new_mail']
|
||||
|
||||
|
||||
if ( len(newmail) <= 0 ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - le nouvel email est vide")
|
||||
return False, " Impossible de mettre à jour l'adresse email du partenaire "
|
||||
|
||||
if( str(newmail) != str(confnewmail)) :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Les emails ne sont pas identiques")
|
||||
return False, " Les emails ne sont pas identiques"
|
||||
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
|
||||
coll_name = dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'email':mymail},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + "L'adresse mail du partenaire a bien ete mis à jour =" + str(ret_val['_id']))
|
||||
return True, "L'adresse mail du partenaire a bien ete mis à jour"
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour l'adresse mail du partenaire recid= : " +str(partner_recid) )
|
||||
return False, " Impossible de mettre à jour l'adresse mail du partenaire"
|
||||
|
||||
|
||||
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 mettre à jour l'adresse mail du partenaire"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
partner Securité :
|
||||
Cette fonction met à jour le mot de passe du partenaire
|
||||
'''
|
||||
def update_partner_pwd(diction):
|
||||
try:
|
||||
# Dictionnaire des champs utilisables
|
||||
'''
|
||||
# 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', 'pwd', 'new_pwd', 'conf_new_pwd']
|
||||
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 accepté "
|
||||
|
||||
'''
|
||||
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', 'pwd', 'new_pwd', 'conf_new_pwd']
|
||||
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, " La valeur '" + val + "' n'est pas presente dans liste "
|
||||
|
||||
# Recuperation du recid du partner
|
||||
mydata = {}
|
||||
mytoken = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mytoken = diction['token']
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||
if( partner_recid is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
mypwd=""
|
||||
if ("pwd" in diction.keys()):
|
||||
if diction['pwd']:
|
||||
mypwd = diction['pwd']
|
||||
|
||||
|
||||
newpwd = ""
|
||||
if ("new_pwd" in diction.keys()):
|
||||
if diction['new_pwd']:
|
||||
newpwd = diction['new_pwd']
|
||||
mydata['pwd'] = diction['new_pwd']
|
||||
|
||||
|
||||
confnewpwd = ""
|
||||
if ("conf_new_pwd" in diction.keys()):
|
||||
if diction['conf_new_pwd']:
|
||||
confnewpwd = diction['conf_new_pwd']
|
||||
|
||||
|
||||
if ( len(newpwd) <= 0 ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - le nouveau mot de passe est vide")
|
||||
return False, " Impossible de mettre à jour le mot de passe "
|
||||
|
||||
if( str(newpwd) != str(confnewpwd)) :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Les mots de passe ne sont pas identiques")
|
||||
return False, " Les mots de passe ne sont pas identiques "
|
||||
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
#print(mydata)
|
||||
|
||||
|
||||
coll_name = dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + "Le mot de passe du partenaire a bien ete mis à jour =" + str(ret_val['_id']))
|
||||
return True, "Le mot de passe du partenaire a bien ete mis à jour"
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le mot de passe du partenaire recid= : " +str(partner_recid) )
|
||||
return False, " Impossible de mettre à jour le mot de passe du partenaire"
|
||||
|
||||
|
||||
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 mettre à jour le mot de passe du partenaire"
|
||||
|
||||
|
||||
'''
|
||||
MAJ d'un partenaire.
|
||||
la clé est l'adresse email principale
|
||||
'''
|
||||
def update_partner_account(diction):
|
||||
try:
|
||||
client = MongoClient(CONNECTION_STRING)
|
||||
|
||||
# Dictionnaire des champs utilisables
|
||||
'''
|
||||
|
@ -190,7 +390,7 @@ def update_partner_account(diction):
|
|||
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, " Creation partner account : Le champ '" + val + "' n'est pas accepté "
|
||||
return False, " Le champ '" + val + "' n'est pas accepté "
|
||||
|
||||
'''
|
||||
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||
|
@ -206,6 +406,7 @@ def update_partner_account(diction):
|
|||
my_email = ""
|
||||
my_token = ""
|
||||
|
||||
|
||||
if ("nom" in diction.keys()):
|
||||
if diction['nom']:
|
||||
my_token = diction['token']
|
||||
|
@ -287,19 +488,11 @@ def update_partner_account(diction):
|
|||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
print(str(datetime.now()) + " webservice : diction = " + str(mydata))
|
||||
#print(str(datetime.now()) + " webservice : diction = " + str(mydata))
|
||||
|
||||
dbname = client['cherifdb']
|
||||
coll_name = dbname['partnair_account']
|
||||
|
||||
'''
|
||||
ret_val = coll_name.find_and_modify(query={'email': str(my_token), 'locked': '0'},
|
||||
update={"$set": mydata}
|
||||
)
|
||||
'''
|
||||
|
||||
print("debut update recid partenaire ="+partner_recid)
|
||||
print(" mydata = "+str(mydata))
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1'},
|
||||
|
|
Loading…
Reference in New Issue