1214 lines
48 KiB
Python
1214 lines
48 KiB
Python
'''
|
|
|
|
Ce fichier definit la gestion des partners - client.
|
|
exemple :
|
|
- creation et modification des compte client
|
|
- connexion pour l'obtention d'un token
|
|
- creation d'une api d'ajout/mise d'une formation
|
|
- creation d'une api de desactivation d'une formation
|
|
|
|
'''
|
|
|
|
from pymongo import MongoClient
|
|
import pymongo
|
|
import json
|
|
from flask import Flask, request, jsonify
|
|
#from flask_mongoengine import MongoEngine
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
import numpy as np
|
|
import ela_index_bdd_classes as ela_index
|
|
import email_mgt as mail
|
|
from datetime import datetime
|
|
import logging
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
from pymongo import ReturnDocument
|
|
from datetime import datetime
|
|
import GlobalVariable as MYSY_GV
|
|
import strype_payement as Stripe
|
|
|
|
|
|
|
|
class JSONEncoder(json.JSONEncoder):
|
|
def default(self, o):
|
|
if isinstance(o, ObjectId):
|
|
return str(o)
|
|
return json.JSONEncoder.default(self, o)
|
|
|
|
|
|
'''
|
|
Ajout d'un partenaire
|
|
'''
|
|
def add_partner_account(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 = ['nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country','link_linkedin','link_facebook','link_twitter',
|
|
'email','pwd', 'telephone','contact_nom','contact_prenom','contact_tel','contact_mail', 'pack_service']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Creation partner account : Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
|
return False, "Impossible de créer le partenaire. Toutes les informations fournies ne sont pas valables"
|
|
|
|
'''
|
|
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 = ['nom', 'email','pwd', 'telephone','contact_nom','contact_prenom','contact_tel','contact_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, "Impossible de créer le partenaire, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# recuperation des paramettre
|
|
mydata = {}
|
|
|
|
mydata['invoice_vat_num'] = ""
|
|
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
mydata['nom'] = diction['nom']
|
|
mydata['invoice_nom'] = diction['nom']
|
|
|
|
if ("adr_street" in diction.keys()):
|
|
if diction['adr_street']:
|
|
mydata['adr_street'] = diction['adr_street']
|
|
mydata['invoice_adr_street'] = diction['adr_street']
|
|
|
|
if ("adr_city" in diction.keys()):
|
|
if diction['adr_city']:
|
|
mydata['adr_city'] = diction['adr_city']
|
|
mydata['invoice_adr_city'] = diction['adr_city']
|
|
|
|
if ("adr_zip" in diction.keys()):
|
|
if diction['adr_zip']:
|
|
mydata['adr_zip'] = diction['adr_zip']
|
|
mydata['invoice_adr_zip'] = diction['adr_zip']
|
|
|
|
if ("adr_country" in diction.keys()):
|
|
if diction['adr_country']:
|
|
mydata['adr_country'] = diction['adr_country']
|
|
mydata['invoice_adr_country'] = diction['adr_country']
|
|
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
mydata['email'] = diction['email']
|
|
mydata['invoice_email'] = diction['email']
|
|
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
mydata['telephone'] = diction['telephone']
|
|
mydata['invoice_telephone'] = diction['telephone']
|
|
|
|
if ("pwd" in diction.keys()):
|
|
if diction['pwd']:
|
|
mydata['pwd'] = diction['pwd']
|
|
|
|
if ("contact_nom" in diction.keys()):
|
|
if diction['contact_nom']:
|
|
mydata['contact_nom'] = diction['contact_nom']
|
|
|
|
if ("contact_prenom" in diction.keys()):
|
|
if diction['contact_prenom']:
|
|
mydata['contact_prenom'] = diction['contact_prenom']
|
|
|
|
if ("contact_tel" in diction.keys()):
|
|
if diction['contact_tel']:
|
|
mydata['contact_tel'] = diction['contact_tel']
|
|
|
|
if ("contact_mail" in diction.keys()):
|
|
if diction['contact_mail']:
|
|
mydata['contact_mail'] = diction['contact_mail']
|
|
|
|
if ("link_linkedin" in diction.keys()):
|
|
if diction['link_linkedin']:
|
|
mydata['link_linkedin'] = diction['link_linkedin']
|
|
|
|
if ("link_facebook" in diction.keys()):
|
|
if diction['link_facebook']:
|
|
mydata['link_facebook'] = diction['link_facebook']
|
|
|
|
if ("link_twitter" in diction.keys()):
|
|
if diction['link_twitter']:
|
|
mydata['link_twitter'] = diction['link_twitter']
|
|
|
|
if ("pack_service" in diction.keys()):
|
|
if diction['pack_service']:
|
|
mydata['pack_service'] = diction['pack_service']
|
|
|
|
|
|
# Creation du RecId du user
|
|
mydata['recid'] = mycommon.create_user_recid()
|
|
|
|
# Creation de la clé d'insertion
|
|
mydata['insert_key'] = mycommon.create_user_recid()
|
|
|
|
mydata['active'] = '0'
|
|
mydata['locked'] = '0'
|
|
mydata['ispending'] = "1"
|
|
|
|
print(str(datetime.now()) + " webservice : diction = "+str(mydata))
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
coll_name_user_account = MYSY_GV.dbname['user_account']
|
|
|
|
# Verification que cette adresse email n'existe pas. Ceci que soit entant que user ou entant que partner
|
|
#tmp = coll_name.find({'email': str(mydata['email']) }).count()
|
|
tmp = coll_name.count_documents({'email': str(mydata['email']), 'active':'1' })
|
|
|
|
logging.info(" TMP = "+str(tmp))
|
|
if( tmp > 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - l'adresse email '"+str(mydata['email'])+"' existe deja, impossible de créer le compte partenaire ")
|
|
return False, "l'adresse email '"+str(mydata['email'])+"' est deja utilisée, impossible de créer le compte partenaire "
|
|
|
|
tmp = coll_name_user_account.count_documents({'email': str(mydata['email']), 'active':'1'})
|
|
logging.info(" TMP = " + str(tmp))
|
|
if (tmp > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - l'adresse email '" + str(
|
|
mydata['email']) + "' existe deja (utilisé comme compte user), impossible de créer le compte partenaire ")
|
|
return False, "l'adresse email '" + str(
|
|
mydata['email']) + "' est deja utilisée, impossible de créer le compte partenaire "
|
|
|
|
|
|
ret_val = coll_name.insert_one(mydata)
|
|
mail.send_partner_account_mail(ret_val.inserted_id, str(mydata['email']))
|
|
return True, " Le partenaire a été créé"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de créer le partenaire"
|
|
|
|
|
|
|
|
'''
|
|
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 = MYSY_GV.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) + " - ERRORRRR AT 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 = MYSY_GV.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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le mot de passe du partenaire"
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet de mettre à jour la clé d'insertion.
|
|
Cette clé est utilisée pour permettre de rattacher une collaborateur à une entreprise
|
|
"""
|
|
def update_partner_insert_key(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', 'current_insert_key', 'new_insert_key', 'conf_insert_key']
|
|
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', 'current_insert_key', 'new_insert_key', 'conf_insert_key']
|
|
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 la clé d'insertion "
|
|
|
|
mykey=""
|
|
if ("current_insert_key" in diction.keys()):
|
|
if diction['current_insert_key']:
|
|
mykey = diction['current_insert_key']
|
|
|
|
|
|
newkey = ""
|
|
if ("new_insert_key" in diction.keys()):
|
|
if diction['new_insert_key']:
|
|
newkey = diction['new_insert_key']
|
|
mydata['insert_key'] = diction['new_insert_key']
|
|
|
|
|
|
confkey = ""
|
|
if ("conf_insert_key" in diction.keys()):
|
|
if diction['conf_insert_key']:
|
|
confkey = diction['conf_insert_key']
|
|
|
|
|
|
if ( len(newkey) <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - la nouvelle clé d'insertion est vide")
|
|
return False, " Impossible de mettre à jour la clé d'insertion "
|
|
|
|
if( str(newkey) != str(confkey)) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La nouvelle clé et la confirmation ne sont pas identiques")
|
|
return False, "La nouvelle clé et la confirmation ne sont pas identiques"
|
|
|
|
|
|
mydata['date_update'] = str(datetime.now())
|
|
|
|
#print(mydata)
|
|
|
|
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
|
|
ret_val = coll_name.find_one_and_update(
|
|
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'insert_key':mykey},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
if (ret_val and ret_val['_id']):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + "La clé d'insertion du partenaire a bien ete mise à jour =" + str(ret_val['_id']))
|
|
return True, "La clé d'insertion a bien été mise à jour"
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la clé d'insertion du partenaire recid= : " +str(partner_recid) )
|
|
return False, " Impossible de mettre à jour la clé d'insertion"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour la clé d'insertion "
|
|
|
|
|
|
|
|
'''
|
|
MAJ d'un partenaire.
|
|
la clé est l'adresse email principale
|
|
'''
|
|
def update_partner_account(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 = ['nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country', 'link_linkedin',
|
|
'email', 'pwd', 'telephone', 'contact_nom', 'contact_prenom', 'contact_tel',
|
|
'contact_mail', 'token', 'link_facebook', 'link_twitter', 'invoice_vat_num',
|
|
'invoice_nom', 'invoice_adr_street', 'invoice_adr_city', 'invoice_adr_zip',
|
|
'invoice_adr_country', 'invoice_email', 'invoice_telephone', 'invoice_vat_num']
|
|
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']
|
|
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 des paramettre
|
|
my_email = ""
|
|
my_token = ""
|
|
|
|
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", my_token)
|
|
|
|
if retval is False :
|
|
return False, " Le token n'est pas valide"
|
|
# Recuperation du recid de l'utilisateur
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
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 "
|
|
|
|
mydata = {}
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
mydata['nom'] = diction['nom']
|
|
|
|
if ("adr_street" in diction.keys()):
|
|
if diction['adr_street']:
|
|
mydata['adr_street'] = diction['adr_street']
|
|
|
|
if ("adr_city" in diction.keys()):
|
|
if diction['adr_city']:
|
|
mydata['adr_city'] = diction['adr_city']
|
|
|
|
if ("adr_zip" in diction.keys()):
|
|
if diction['adr_zip']:
|
|
mydata['adr_zip'] = diction['adr_zip']
|
|
|
|
if ("adr_country" in diction.keys()):
|
|
if diction['adr_country']:
|
|
mydata['adr_country'] = diction['adr_country']
|
|
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
my_email = diction['email']
|
|
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
mydata['telephone'] = diction['telephone']
|
|
|
|
if ("pwd" in diction.keys()):
|
|
if diction['pwd']:
|
|
mydata['pwd'] = diction['pwd']
|
|
|
|
if ("contact_nom" in diction.keys()):
|
|
if diction['contact_nom']:
|
|
mydata['contact_nom'] = diction['contact_nom']
|
|
|
|
if ("contact_prenom" in diction.keys()):
|
|
if diction['contact_prenom']:
|
|
mydata['contact_prenom'] = diction['contact_prenom']
|
|
|
|
if ("contact_tel" in diction.keys()):
|
|
if diction['contact_tel']:
|
|
mydata['contact_tel'] = diction['contact_tel']
|
|
|
|
if ("contact_mail" in diction.keys()):
|
|
if diction['contact_mail']:
|
|
mydata['contact_mail'] = diction['contact_mail']
|
|
|
|
if ("link_linkedin" in diction.keys()):
|
|
if diction['link_linkedin']:
|
|
mydata['link_linkedin'] = diction['link_linkedin']
|
|
|
|
if ("link_facebook" in diction.keys()):
|
|
if diction['link_facebook']:
|
|
mydata['link_facebook'] = diction['link_facebook']
|
|
|
|
if ("link_twitter" in diction.keys()):
|
|
if diction['link_twitter']:
|
|
mydata['link_twitter'] = diction['link_twitter']
|
|
|
|
if ("invoice_vat_num" in diction.keys()):
|
|
if diction['invoice_vat_num']:
|
|
mydata['invoice_vat_num'] = diction['invoice_vat_num']
|
|
|
|
if ("invoice_nom" in diction.keys()):
|
|
if diction['invoice_nom']:
|
|
mydata['invoice_nom'] = diction['invoice_nom']
|
|
|
|
if ("invoice_adr_street" in diction.keys()):
|
|
if diction['invoice_adr_street']:
|
|
mydata['invoice_adr_street'] = diction['invoice_adr_street']
|
|
|
|
if ("invoice_adr_city" in diction.keys()):
|
|
if diction['invoice_adr_city']:
|
|
mydata['invoice_adr_city'] = diction['invoice_adr_city']
|
|
|
|
if ("invoice_adr_zip" in diction.keys()):
|
|
if diction['invoice_adr_zip']:
|
|
mydata['invoice_adr_zip'] = diction['invoice_adr_zip']
|
|
|
|
if ("invoice_adr_zip" in diction.keys()):
|
|
if diction['invoice_adr_country']:
|
|
mydata['invoice_adr_country'] = diction['invoice_adr_country']
|
|
|
|
if ("invoice_email" in diction.keys()):
|
|
if diction['invoice_email']:
|
|
mydata['invoice_email'] = diction['invoice_email']
|
|
|
|
if ("invoice_telephone" in diction.keys()):
|
|
if diction['invoice_telephone']:
|
|
mydata['invoice_telephone'] = diction['invoice_telephone']
|
|
|
|
|
|
|
|
mydata['date_update'] = str(datetime.now())
|
|
|
|
|
|
|
|
|
|
#print(str(datetime.now()) + " webservice : diction = " + str(mydata))
|
|
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
|
|
"""
|
|
Si le compte partenaire n'as pas de compte de payement stripe, alors on profite de cette mise à jour pour le faire
|
|
"""
|
|
tmp = coll_name.find({'recid':str(partner_recid)})
|
|
print('### tmp = '+str(tmp[0]))
|
|
|
|
partnair_stripe_id = ""
|
|
if ("stripe_account_id" in tmp[0].keys()):
|
|
if tmp[0]['stripe_account_id']:
|
|
partnair_stripe_id = tmp[0]['stripe_account_id']
|
|
|
|
if ( partnair_stripe_id is False or len(partnair_stripe_id) < 5):
|
|
print('### le partenaire = ' + str(tmp[0]['nom']) + " n'as pas de compte Stripe. on va le créer")
|
|
"""
|
|
Creation du compte de payement Stripe
|
|
"""
|
|
|
|
my_stripe_data = {}
|
|
my_stripe_data['email'] = str(tmp[0]['email'])
|
|
my_stripe_data['name'] = str(tmp[0]['nom'])
|
|
|
|
my_stripe_data['city'] = ""
|
|
if ("adr_city" in tmp[0].keys()):
|
|
if tmp[0]['adr_city']:
|
|
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
|
|
|
my_stripe_data['country'] = ""
|
|
if ("adr_country" in tmp[0].keys()):
|
|
if tmp[0]['adr_country']:
|
|
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
|
|
|
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
|
mydata['stripe_account_id'] = part_stripe_account_id
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client " + str(
|
|
tmp[0]['nom']))
|
|
|
|
|
|
|
|
ret_val = coll_name.find_one_and_update(
|
|
{'recid': str(partner_recid), 'locked': '0', 'active': '1'},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (ret_val and ret_val['_id']):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + "Le partenaire a bien ete mise à jour =" + str(ret_val['_id']))
|
|
return True, "Le partenaire a bien ete mise à jour"
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le partenaire recid= : " +str(partner_recid) )
|
|
return False, " Impossible de mettre à jour le partenaire"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le partenaire"
|
|
|
|
|
|
'''
|
|
cette fonction valide un compte partenaire
|
|
La modification ne s'effectue que si le compte n'est pas verrouillé.
|
|
'locked'=0
|
|
|
|
|
|
/!\ : Juste apres la validation, le compte de payement est créé dans Stripe
|
|
|
|
'''
|
|
def valide_partnair_account(value):
|
|
try:
|
|
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
|
|
tmp_count = coll_name.count_documents({'_id':ObjectId(str(value)), 'active':'1'})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce compte a deja été activé")
|
|
return False, "Ce compte a deja été activé "
|
|
|
|
|
|
tmp_count = coll_name.count_documents({'_id':ObjectId(str(value)), 'active':'0'})
|
|
|
|
if( tmp_count <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - il n'y aucun compte à activer")
|
|
return False, "Impossible de valider ce compte "
|
|
|
|
tmp = coll_name.find({'_id': ObjectId(str(value)), 'active': '0'})
|
|
partner_email = tmp[0]['email']
|
|
|
|
print(" ########## Email = "+str(tmp[0]['email']))
|
|
print(" ########## recid = " + str(tmp[0]['recid']))
|
|
|
|
# A ce niveau le login et passe sont ok.
|
|
# il faut donc créer le token et renvoyer le token.
|
|
my_token = mycommon.create_token_urlsafe()
|
|
|
|
"""
|
|
Creation du compte de payement Stripe
|
|
"""
|
|
|
|
my_stripe_data = {}
|
|
my_stripe_data['email'] = str(tmp[0]['email'])
|
|
my_stripe_data['name'] = str(tmp[0]['nom'])
|
|
|
|
my_stripe_data['city'] = ""
|
|
if ("adr_city" in tmp[0].keys()):
|
|
if tmp[0]['adr_city']:
|
|
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
|
|
|
|
|
my_stripe_data['adr_country'] = ""
|
|
if ("adr_country" in tmp[0].keys()):
|
|
if tmp[0]['adr_country']:
|
|
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
|
|
|
|
|
|
|
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
|
if( local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client "+str(tmp[0]['nom']))
|
|
|
|
|
|
'''
|
|
Create default / temporary pwd for new account
|
|
'''
|
|
#my_tmp_pwd = mycommon.create_token_urlsafe();
|
|
|
|
now = datetime.now()
|
|
ret_val = coll_name.find_one_and_update({'_id':ObjectId(str(value)), 'locked':'0'},
|
|
{"$set":
|
|
{'active': "1","date_update":str(now),
|
|
'token':str(my_token),
|
|
'stripe_account_id':part_stripe_account_id,
|
|
}
|
|
},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if( ret_val and ret_val['_id']):
|
|
mycommon.myprint("La modif a bien ete faite Ajout Token OK, ="+str(ret_val['_id']))
|
|
# Envoie du mail de notification
|
|
mail.Pro_Account_Token_Pass(partner_email, my_token)
|
|
return 'True', my_token
|
|
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucune modif n'a été faite")
|
|
return False, "Impossible de valider le compte"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de valider le compte"
|
|
|
|
|
|
|
|
|
|
'''
|
|
Recuperation d'un partenaire
|
|
'''
|
|
def get_partner_account(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token']
|
|
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'existe pas, requete annulée")
|
|
return False, " Impossible de recuperer les informations"
|
|
|
|
'''
|
|
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']
|
|
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, " Impossible de recuperer les informations"
|
|
|
|
# recuperation des paramettre
|
|
email_value = ""
|
|
|
|
|
|
token_value = ""
|
|
if diction['token']:
|
|
token_value = diction['token']
|
|
|
|
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
|
|
# Verification de la valididé du token
|
|
coll_token = MYSY_GV.dbname['user_token']
|
|
|
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
|
retval = mycommon.check_partner_token_validity(email_value, token_value )
|
|
|
|
if retval is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
|
return False, " Impossible de recuperer les informations"
|
|
|
|
|
|
'''tmp_count = coll_token.find({'email':email_value, 'token': token_value, 'valide': '1'}).count()
|
|
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint("L'email ou le token ne sont pas valident")
|
|
return False
|
|
'''
|
|
|
|
coll_token = MYSY_GV.dbname['partner_token']
|
|
tmp = coll_token.find({ 'token': str(token_value), 'valide': '1'})
|
|
partnere_recid = tmp[0]['recid']
|
|
|
|
print(" parters RECID = "+str(partnere_recid))
|
|
|
|
is_first_connexion = True
|
|
|
|
RetObject = []
|
|
for retVal in coll_name.find({'recid': str(partnere_recid)}):
|
|
#mycommon.myprint (str(retVal))
|
|
if ("firstconnexion" in retVal.keys()):
|
|
if retVal['firstconnexion'] and str(retVal['firstconnexion'] == "0"):
|
|
is_first_connexion = False
|
|
|
|
user = retVal
|
|
RetObject.append(JSONEncoder().encode(user))
|
|
|
|
"""
|
|
Si la première connexion, alors on met la le champs avec la valeur firstconnexion = 0
|
|
"""
|
|
my_new_data = {}
|
|
now = str(datetime.now())
|
|
|
|
if( is_first_connexion is True):
|
|
my_new_data = {'firstconnexion':'0', 'lastconnexion':now}
|
|
else:
|
|
my_new_data = {'lastconnexion': now}
|
|
|
|
ret_val = coll_name.find_one_and_update({'recid': str(partnere_recid)},
|
|
{"$set": my_new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ret_val and ret_val['_id']:
|
|
mycommon.myprint("Connexion du partner recid = "+str(partnere_recid)+" OK. Mise à jour du firstconnexion et/ou lastconnexion : OK")
|
|
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) +
|
|
" WARNING : Impossible de mettre à jour du firstconnexion et/ou lastconnexion du partner recid = "+str(partnere_recid)+". ")
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer les informations"
|
|
|
|
|
|
|
|
'''
|
|
|
|
Login du partenaire avec
|
|
- mail
|
|
- passwd
|
|
- cle secrete qui est son token fixe'''
|
|
def partner_login(diction):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['email', 'pwd', 'secret']
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# 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.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Impossible de se connecter"
|
|
|
|
'''
|
|
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 = ['email', 'pwd', 'secret']
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans liste des champs")
|
|
return False, "Impossible de se connecter"
|
|
|
|
|
|
mydata={}
|
|
|
|
# recuperation des paramettre
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
mydata['email'] = diction['email']
|
|
|
|
|
|
if ("pwd" in diction.keys()):
|
|
if diction['pwd']:
|
|
pwd = diction['pwd']
|
|
|
|
if ("secret" in diction.keys()):
|
|
if diction['secret']:
|
|
token = diction['secret']
|
|
mydata['token'] = diction['secret']
|
|
|
|
now = str(datetime.now())
|
|
|
|
mydata['valide'] = "1"
|
|
mydata['date_update'] = now
|
|
|
|
|
|
# Verification que les informations sont juste
|
|
coll_name = MYSY_GV.dbname['partnair_account']
|
|
ret_val = coll_name.find_one_and_update({'email': str(email), 'pwd': str(pwd), 'token': str(token), 'active': '1', 'locked':'0'},
|
|
{"$set": {'last_connexion':str(now)}},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ret_val and ret_val['_id']:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Connexion partnair "+email+" : OK, Date : "+ str(now)+" , _id = " + str(ret_val['_id']))
|
|
# Vu que les credentials sont ok, alors enregistrement de la connexion dans la table "partner token"
|
|
|
|
#print(" GRRRRRRRRRRRRRRRRRRR "+str(ret_val))
|
|
mydata['recid'] = str(ret_val['recid'])
|
|
token_collection = MYSY_GV.dbname['partner_token']
|
|
|
|
ret_val2 = token_collection.find_one_and_update({'recid': str(mydata['recid']), 'valide': '1', 'locked':'0'},
|
|
{"$set": mydata},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ret_val2 and ret_val2['_id']:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Connexion partener_token : OK , _id = " + str(ret_val2['_id']))
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible d'enregistrer le token du partenare dans partener_token ")
|
|
return False, " Impossible de se connecter"
|
|
|
|
|
|
return True, " Partner Connexion : OK"
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de se connecter - Partner ")
|
|
return False, " Impossible de se connecter"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la formation"
|
|
|
|
|
|
"""
|
|
Cette fonction upgrade un compte utilisateur vers
|
|
un compte PRO (aussi appelé compte partenaire).
|
|
|
|
Ceci revient à créer un nouveau compte utilisateur. aini la personne en face
|
|
aura
|
|
- un compte utilisateur classique et
|
|
- un compte pro
|
|
|
|
En suite on desactive le compte utilisateur classique et on maintient que le compte pro.
|
|
|
|
Pour migrer un compte utilisateur classique vers un compte pro, voici ce qu'il faut faire :
|
|
|
|
1 - recuperer les infos du contact . ici à partir du token de la personne connectée, on peut aller chercher ses info.
|
|
2 - recuperer les infos de la société
|
|
3 - recuperer les infos sur pack
|
|
|
|
etape 1 : add_partner_account(diction)
|
|
etape 2 : Desactivation du compte utilisateur
|
|
"""
|
|
def UpgradetoPro(diction):
|
|
try:
|
|
field_list = ['token', 'nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country', 'link_linkedin', 'link_facebook',
|
|
'link_twitter', 'email', 'pwd', 'telephone', 'contact_nom', 'contact_prenom', 'contact_tel',
|
|
'contact_mail', 'pack_service']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Creation partner account : Le champ '" + val + "' n'existe pas, UpgradetoPro annulée")
|
|
return False, "Impossible de créer le partenaire"
|
|
|
|
'''
|
|
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', 'nom', 'adr_street', 'adr_city', 'adr_zip', 'adr_country',
|
|
'email', 'telephone', 'pack_service']
|
|
|
|
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, "Impossible de créer le partenaire"
|
|
|
|
token = ""
|
|
new_diction = {}
|
|
user_recid = "None"
|
|
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
if ( len(str(token)) > 0 ):
|
|
retval = mycommon.check_token_validity("", token)
|
|
|
|
if retval is False :
|
|
mycommon.myprint(str(inspect.stack()[0][3])+" - Le token n'est pas valide")
|
|
return False, "Le token n'est pas valide"
|
|
|
|
# Recuperation du recid de l'utilisateur
|
|
user_recid = mycommon.get_user_recid_from_token(token)
|
|
if user_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3])+" - Impossible de recuperer le token de l'utilisateur")
|
|
return False, " Impossible de migrer vers le compte pro"
|
|
|
|
|
|
# Recuperation des paramettre du compe
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
new_diction['nom'] = diction['nom']
|
|
|
|
if ("adr_street" in diction.keys()):
|
|
if diction['adr_street']:
|
|
new_diction['adr_street'] = diction['adr_street']
|
|
|
|
if ("adr_city" in diction.keys()):
|
|
if diction['adr_city']:
|
|
new_diction['adr_city'] = diction['adr_city']
|
|
|
|
if ("adr_zip" in diction.keys()):
|
|
if diction['adr_zip']:
|
|
new_diction['adr_zip'] = diction['adr_zip']
|
|
|
|
if ("adr_country" in diction.keys()):
|
|
if diction['adr_country']:
|
|
new_diction['adr_country'] = diction['adr_country']
|
|
|
|
if ("link_linkedin" in diction.keys()):
|
|
if diction['link_linkedin']:
|
|
new_diction['link_linkedin'] = diction['link_linkedin']
|
|
|
|
if ("link_facebook" in diction.keys()):
|
|
if diction['link_facebook']:
|
|
new_diction['link_facebook'] = diction['link_facebook']
|
|
|
|
if ("link_twitter" in diction.keys()):
|
|
if diction['link_twitter']:
|
|
new_diction['link_twitter'] = diction['link_twitter']
|
|
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
new_diction['email'] = diction['email']
|
|
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
new_diction['telephone'] = diction['telephone']
|
|
|
|
|
|
if ("pack_service" in diction.keys()):
|
|
if diction['pack_service']:
|
|
new_diction['pack_service'] = diction['pack_service']
|
|
|
|
'''
|
|
Create default pwd for new account
|
|
'''
|
|
new_diction['pwd'] = mycommon.create_token_urlsafe();
|
|
|
|
|
|
'''
|
|
Recuperation des information du contact.
|
|
Pour memo, le compte utilisateur qui fait cette migration devient automatiquement
|
|
le contact principal du compte pro.
|
|
'''
|
|
coll_user_account = MYSY_GV.dbname['user_account']
|
|
for x in coll_user_account.find({"recid": user_recid}):
|
|
if ("email" in x.keys()):
|
|
if x['email']:
|
|
new_diction['contact_mail'] = x['email']
|
|
|
|
if ("last_name" in x.keys()):
|
|
if x['last_name']:
|
|
new_diction['contact_nom'] = x['last_name']
|
|
|
|
if ("surname" in x.keys()):
|
|
if x['surname']:
|
|
new_diction['contact_prenom'] = x['surname']
|
|
|
|
if ("mob_phone" in x.keys()):
|
|
if x['mob_phone']:
|
|
new_diction['contact_tel'] = x['mob_phone']
|
|
|
|
print(" new_diction la = "+str(new_diction))
|
|
|
|
'''
|
|
Verification que cette adresse email n'hesiste pas deja dans
|
|
'''
|
|
check_tmp = coll_user_account.count_documents({'email': str(diction['email'])})
|
|
|
|
if (check_tmp < 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce compte partenaire existe deja")
|
|
return False, "Ce compte partenaire existe deja"
|
|
|
|
status, retval = add_partner_account(new_diction)
|
|
|
|
if( status ):
|
|
'''
|
|
La migration s'est bien passée.
|
|
Maintenant mettre le compte utilisateur :
|
|
- "migrated : 1"
|
|
- "migrated_mail_account" : le mail du compte pro associé
|
|
- "migration_date" : datetime.now()
|
|
|
|
'''
|
|
mydata = {}
|
|
mydata['migrated'] = "1"
|
|
mydata['ispending'] = "1"
|
|
mydata['migrated_date'] = str(datetime.now())
|
|
mydata['migrated_mail_account'] = new_diction['email']
|
|
ret_val = coll_user_account.find_one_and_update(
|
|
{"recid": user_recid},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER )
|
|
if (ret_val and ret_val['_id']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " le compte recid "+str(user_recid)+" migré en compte pro "+str(mydata))
|
|
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de migrer le user_account : " + str(user_recid)+" en compte pro")
|
|
return False, " Impossible de finaliser la migration vers le compte PRO : "
|
|
|
|
|
|
else:
|
|
return False, "Impossible de migrer le compte vers le compte pro"
|
|
|
|
return True, "Le compte à été bien migré vers un compte pro"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de migrer vers le compte pro"
|