inscription utilisateur complète
This commit is contained in:
@@ -3,14 +3,27 @@ from glob import glob
|
||||
import tempfile
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
import smtplib
|
||||
|
||||
from .paheko import Paheko
|
||||
from .ldap import Ldap
|
||||
from .mattermost import Mattermost
|
||||
from .sympa import Sympa
|
||||
from .template import render_template
|
||||
from .config import getDockersConfig, getSecretConfig
|
||||
|
||||
DEFAULT_FILE = "/kaz/tmp/createUser.txt"
|
||||
|
||||
webmail_url = f"https://webmail.{getDockersConfig('domain')}"
|
||||
mattermost_url = f"https://agora.{getDockersConfig('domain')}"
|
||||
mdp_url = f"https://mdp.{getDockersConfig('domain')}"
|
||||
sympa_url = f"https://listes.{getDockersConfig('domain')}"
|
||||
site_url = f"https://{getDockersConfig('domain')}"
|
||||
cloud_url = f"https://cloud.{getDockersConfig('domain')}"
|
||||
|
||||
|
||||
def _generate_password(self):
|
||||
cmd="apg -n 1 -m 10 -M NCL -d"
|
||||
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||
@@ -81,36 +94,45 @@ def create_user(email, email_secours, admin_orga, nom_orga, quota_disque, nom, p
|
||||
mm.add_user_to_team(email, nom_orga)
|
||||
|
||||
|
||||
# #on inscrit email et email_secours à la nl sympa_liste_info
|
||||
# res, status_code = self.sympa_user_resource.post(email,sympa_liste_info)
|
||||
# if status_code != 200: raise ValueError(f"ERREUR 9 sur Sympa: {email} : {res}, on arrête tout ")
|
||||
# res, status_code = self.sympa_user_resource.post(email_secours,sympa_liste_info)
|
||||
# if status_code != 200: raise ValueError(f"ERREUR 10 sur Sympa: {email_secours} : {res}, on arrête tout ")
|
||||
#
|
||||
# #on construit/envoie le mail
|
||||
# context = {
|
||||
# 'ADMIN_ORGA': tab['admin_orga'],
|
||||
# 'NOM': tab['nom'],
|
||||
# 'EMAIL_SOUHAITE': email,
|
||||
# 'PASSWORD': password,
|
||||
# 'QUOTA': tab['quota_disque'],
|
||||
# 'URL_WEBMAIL': webmail_url,
|
||||
# 'URL_AGORA': mattermost_url,
|
||||
# 'URL_MDP': mdp_url,
|
||||
# 'URL_LISTE': sympa_url,
|
||||
# 'URL_SITE': site_url,
|
||||
# 'URL_CLOUD': cloud_url
|
||||
# }
|
||||
# subject="KAZ: confirmation d'inscription !"
|
||||
# sender=app.config['MAIL_USERNAME']
|
||||
# reply_to = app.config['MAIL_REPLY_TO']
|
||||
# msg = Message(subject=subject, sender=sender, reply_to=reply_to, recipients=[email,email_secours])
|
||||
# msg.html = render_template('email_inscription.html', **context)
|
||||
# mail.send(msg)
|
||||
#on inscrit email et email_secours à la nl sympa_liste_info
|
||||
sympa = Sympa()
|
||||
sympa.add_email_to_list(email)
|
||||
sympa.add_email_to_list(email_secours)
|
||||
|
||||
#on construit/envoie le mail
|
||||
context = {
|
||||
'ADMIN_ORGA': admin_orga,
|
||||
'NOM': f"{prenom} {nom}",
|
||||
'EMAIL_SOUHAITE': email,
|
||||
'PASSWORD': password,
|
||||
'QUOTA': quota_disque,
|
||||
'URL_WEBMAIL': webmail_url,
|
||||
'URL_AGORA': mattermost_url,
|
||||
'URL_MDP': mdp_url,
|
||||
'URL_LISTE': sympa_url,
|
||||
'URL_SITE': site_url,
|
||||
'URL_CLOUD': cloud_url,
|
||||
}
|
||||
|
||||
html = render_template("email_inscription.html", context)
|
||||
raw = render_template("email_inscription.txt", context)
|
||||
|
||||
message = MIMEMultipart()
|
||||
message["Subject"] = "KAZ: confirmation d'inscription !"
|
||||
message["From"] = f"contact@{getDockersConfig('domain')}"
|
||||
message["To"] = f"{email}, {email_secours}"
|
||||
message.attach(MIMEText(raw, "plain"))
|
||||
message.attach(MIMEText(html, "html"))
|
||||
|
||||
with smtplib.SMTP(f"mail.{getDockersConfig('domain')}", 25) as server:
|
||||
server.sendmail(f"contact@{getDockersConfig('domain')}", [email,email_secours], message.as_string())
|
||||
|
||||
#on met le flag paheko action à Aucune
|
||||
# paheko = Paheko()
|
||||
# paheko.set_user(email, "action_auto", "Aucune")
|
||||
paheko = Paheko()
|
||||
try:
|
||||
paheko.set_user(email, "action_auto", "Aucune")
|
||||
except:
|
||||
print(f"Erreur paheko pour remettre action_auto = Aucune pour {email}")
|
||||
|
||||
#on post sur MM pour dire ok
|
||||
with Mattermost() as mm:
|
||||
|
Reference in New Issue
Block a user