21/03/23 - 22h

master
cherif 2023-03-21 22:18:04 +01:00
parent 2e0c9500b6
commit 69f1684618
8 changed files with 3465 additions and 4 deletions

View File

@ -2,7 +2,14 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="19/03/23 - 19h45">
<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$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" beforeDir="false" afterPath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/strype_payement.py" beforeDir="false" afterPath="$PROJECT_DIR$/strype_payement.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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -316,7 +316,7 @@ elif (MYSY_ENV == "DEV"):
MYSY_MARIADB_USER_PASS = "fB5z%M)GG&g!n2c"
MYSY_MARIADB_HOST = "192.168.1.21"
MYSY_MARIADB_PORT = 3306
MYSY_LMS_BDD = "mysy_db_chamilo_rec_dev"
MYSY_LMS_BDD = "mysy_db_chamilo_dev"
elif (MYSY_ENV == "REC"):

File diff suppressed because one or more lines are too long

View File

@ -2052,6 +2052,63 @@ def EmailChangeAbonnementQty( partners_email, partners_pack_service, partners_da
return False, " Impossible d'envoyer l'email de notification "
"""
Cette fonction notifier à un partenaire la modification de son abonnement. Cas du changement de plan.
par exemple : gold vers standard...
"""
def EmailChangeAbonnementPlan( partners_email, partners_pack_service, partners_nom, qty ):
try:
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow_day = tomorrow.strftime("%A")
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
# msg = MIMEMultipart("alternative")
msg = EmailMessage()
# JINJA2
templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "Template/MySy_Update_Plan_Abonnement_tpl.html"
template = templateEnv.get_template(TEMPLATE_FILE)
# This data can come from database query
body = {
"params":{"user_name": str(partners_nom),
"packs": str(partners_pack_service),
"email": str(partners_email),
"qty": str(qty),
},
}
sourceHtml = template.render(params=body["params"])
msg.set_content(sourceHtml, subtype='html')
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
msg['Bcc'] = 'contact@mysy-training.com'
msg['Subject'] = "[MySy Training Technology] : Modification de votre abonnement "+str(partners_pack_service)
msg['To'] = str(partners_email)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
val = smtpserver.send_message(msg)
smtpserver.close()
print(" Email envoyé " + str(val))
return True
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 d'envoyer l'email de notification "
"""
Cette fonction envoie la notification d'evaluation à un institut de formation
"""

View File

@ -132,6 +132,15 @@ def Create_MySy_LMS_User(diction):
salt = bcrypt.gensalt()
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
print(" ### SALT = ", salt)
print(" ### hashed_pwd = ", hashed_pwd)
salt = salt.decode("UTF-8")
hashed_pwd = hashed_pwd.decode("UTF-8")
print(" ### SALT DECO = ", salt)
print(" ### hashed_pwd DECO = ", hashed_pwd)
if (retval is None or "current_val" not in retval.keys()):
mycommon.myprint(" Impossible de recuperer la sequence 'mysy_sequence' ")
@ -188,7 +197,7 @@ def Create_MySy_LMS_User(diction):
"active = '1';"
try:
#print(" ### my_query = ", my_query)
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:
@ -226,8 +235,8 @@ def Create_MySy_LMS_User(diction):
# Crementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
new_sequence_value = int(current_seq_value)+1
print(" ### current_seq_value = ", current_seq_value)
new_sequence_value = int(mycommon.tryInt(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'},
@ -326,6 +335,9 @@ def Update_Passwd_MySy_LMS_User(diction):
salt = bcrypt.gensalt()
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
salt = salt.decode('UTF-8')
hashed_pwd = hashed_pwd.decode('UTF-8')
conn = mariadb.connect(
user=MYSY_GV.MYSY_MARIADB_USER,
@ -405,6 +417,9 @@ def Enable_MySy_LMS_User(diction):
salt = bcrypt.gensalt()
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
#salt = salt.decode('UTF-8')
#hashed_pwd = hashed_pwd.decode('UTF-8')
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

13
main.py
View File

@ -2695,6 +2695,19 @@ def strip_update_subscription_qty():
localStatus, message = Stripe.strip_update_subscription_qty(payload)
return jsonify(status=localStatus, message=message)
"""
Cette API permet de changer l'abonnement d'un client. c'est a dire le passage
de gold vers standart par exemple
"""
@app.route('/myclass/api/strip_update_subscription_plan/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_update_subscription_plan():
# On recupere le corps (payload) de la requete
payload = request.form.to_dict()
print(" ### strip_update_subscription_plan : payload = ",payload)
localStatus, message = Stripe.strip_update_subscription_plan(payload)
return jsonify(status=localStatus, message=message)
if __name__ == '__main__':

View File

@ -882,6 +882,120 @@ def strip_update_subscription_qty(diction):
return False, " Impossible de changer la quantité de l'abonnement "
"""
Cette fonction permet de changer l'abonnement d'un partenaire.
Par exemple cas d'un "standard" qui passe "Gold" ou vice-versa
"""
def strip_update_subscription_plan(diction):
try:
field_list_obligatoire = ['token','pack', 'qty']
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 , toutes le données obligatoire ne sont pas fournies ")
return False, " Toutes le données obligatoire ne sont pas fournies"
mytoken = ""
if ("token" in diction.keys()):
if diction['token']:
mytoken = diction['token']
pack = ""
if ("pack" in diction.keys()):
if diction['pack']:
pack = diction['pack']
qty = ""
if ("qty" in diction.keys()):
if diction['qty']:
qty = diction['qty']
retval = mycommon.check_partner_token_validity("", str(mytoken))
if retval is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
return False, "Les informations d'identification ne sont pas valident"
# Recuperation du recid du partenaire
partner_recid = mycommon.get_parnter_recid_from_token(str(mytoken))
if partner_recid is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du partenaire")
return False, " Les informations d'identification sont incorrectes"
# recuperation de la susbscription du client
local_ret_val = MYSY_GV.dbname['partnair_account'].find_one(
{'token': mytoken, 'active': '1', 'locked': '0'})
if (local_ret_val['stripe_subscription_id'] is None):
mycommon.myprint(
str(inspect.stack()[0][3]) + " Impossible d'annuler le payement ")
return False, " Impossible de changer l'abonnement "
"""
pack = ""
if ("pack_service" in local_ret_val.keys()):
if local_ret_val['pack_service']:
pack = local_ret_val['pack_service']
qty = ""
if ("nb_formation" in local_ret_val.keys()):
if local_ret_val['nb_formation']:
qty = local_ret_val['nb_formation']
"""
price_id = ""
if (str(pack).lower() == "gold"):
price_id = MYSY_GV.STRIPE_GOLD_PRICE_ID
elif (str(pack).lower() == "standard"):
price_id = MYSY_GV.STRIPE_STANDARD_PRICE_ID
elif (str(pack).lower() == "test"):
price_id = MYSY_GV.STRIPE_TEST_PRICE_ID
print(" ### pack = ", pack, " ## price_id = ", price_id)
print(" #### str(local_ret_val['stripe_subscription_id']) = ", str(local_ret_val['stripe_subscription_id']))
current_subscription = stripe.Subscription.retrieve(str(local_ret_val['stripe_subscription_id']))
#a = stripe.SubscriptionSchedule.release( str(local_ret_val['stripe_subscription_id']), )
a = stripe.Subscription.modify(
str(local_ret_val['stripe_subscription_id']),
proration_behavior='create_prorations',
items=[{
'id': current_subscription['items'].data[0].id,
'price': price_id,
'quantity': qty,
}]
)
#print(" ### aa = ", a)
arret_abonnement = datetime.today().date() + relativedelta(months=+1)
arrete_abonnement_formated = arret_abonnement.strftime("%d/%m/%Y")
now = datetime.now()
partners_email = local_ret_val['email']
partners_nom = local_ret_val['nom']
partners_pack_service = local_ret_val['pack_service']
local_ret_val = email_mgt.EmailChangeAbonnementPlan( partners_email, partners_pack_service, partners_nom, qty, )
if( local_ret_val is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - WARNING : changement qté abonnement, Impossible d'envoyer le mail de notification au partenaire")
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de changer l'abonnement "

View File

@ -700,6 +700,10 @@ def mysylmsdb():
salt = bcrypt.gensalt()
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
salt = salt.encode('UTF-8')
hashed_pwd = hashed_pwd.encode('UTF-8')
print(" ## HASHED hashed = ", str(hashed_pwd), " SALT = , ", str(salt))