inscription utilisateur complète
This commit is contained in:
@@ -10,7 +10,14 @@ mmctl = "docker exec -i mattermostServ bin/mmctl"
|
||||
class Mattermost:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self.authenticate()
|
||||
return self
|
||||
|
||||
def __exit__(self, tp, e, traceback):
|
||||
self.logout()
|
||||
|
||||
|
||||
def authenticate(self):
|
||||
@@ -19,6 +26,11 @@ class Mattermost:
|
||||
subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT, check=True)
|
||||
|
||||
|
||||
def logout(self):
|
||||
# Authentification sur MM
|
||||
cmd = f"{mmctl} auth clean"
|
||||
subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT, check=True)
|
||||
|
||||
def post_message(self, message, equipe="kaz", canal="creation-comptes"):
|
||||
"""
|
||||
Envoyer un message dans une Equipe/Canal de MM
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import subprocess
|
||||
from email_validator import validate_email, EmailNotValidError
|
||||
|
||||
from .config import getDockersConfig, getSecretConfig
|
||||
|
||||
@@ -7,7 +8,9 @@ sympa_pass = getSecretConfig("sympaServ", "SOAP_PASSWORD")
|
||||
sympa_listmaster = getSecretConfig("sympaServ", "ADMINEMAIL")
|
||||
sympa_url = f"https://{getDockersConfig('sympaHost')}.{getDockersConfig('domain')}"
|
||||
sympa_soap = "docker exec -i sympaServ /usr/lib/sympa/bin/sympa_soap_client.pl"
|
||||
sympa_liste_info = f"info@{getDockersConfig('domain_sympa')}"
|
||||
sympa_domain = getDockersConfig('domain_sympa')
|
||||
sympa_liste_info = "infos"
|
||||
|
||||
|
||||
# docker exec -i sympaServ /usr/lib/sympa/bin/sympa_soap_client.pl --soap_url=${httpProto}://${URL_LISTE}/sympasoap --trusted_application=${sympa_SOAP_USER} --trusted_application_password=${sympa_SOAP_PASSWORD} --proxy_vars=\"USER_EMAIL=${LISTMASTER}\" --service=add --service_parameters=\"${NL_LIST},${EMAIL_SOUHAITE}\"" | tee -a "${CMD_SYMPA}"
|
||||
|
||||
@@ -23,14 +26,14 @@ class Sympa:
|
||||
"""
|
||||
Ajouter un email dans une liste sympa
|
||||
"""
|
||||
output = self._execute_sympa_command(email, liste, 'add')
|
||||
output = self._execute_sympa_command(email, f"{liste}@{sympa_domain}", 'add')
|
||||
return output
|
||||
|
||||
def delete_email_from_list(self, email, liste=sympa_liste_info):
|
||||
"""
|
||||
Supprimer un email dans une liste sympa
|
||||
"""
|
||||
output = self._execute_sympa_command(email, liste, 'del')
|
||||
output = self._execute_sympa_command(email, f"{liste}@{sympa_domain}", 'del')
|
||||
return output
|
||||
|
||||
|
||||
|
8
bin/lib/template.py
Normal file
8
bin/lib/template.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import jinja2
|
||||
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="../templates")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
|
||||
def render_template(filename, args):
|
||||
template = templateEnv.get_template(filename)
|
||||
return template.render(args)
|
@@ -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