Commit 447d028d authored by Daniel STAN's avatar Daniel STAN
Browse files

[creer_compte_wiki] Réparation

Le script creer_compte_wiki ne marchait plus depuis la mise en place des tickets
par moinmoin. On le répare en rajoutant une nouvelle action chargée spécialement
de la création de ce compte. À terme, il faut remplacer creer_compte_wiki.py
par une appli dans l'intranet qui ferait automatiquement la liaison avec
un compte crans.
parent 0b22dda0
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - create account action
modified version for Cr@ns callback only (by creer_compte_wiki.py)
@copyright: 2007 MoinMoin:JohannesBerg
@license: GNU GPL, see COPYING for details.
"""
from MoinMoin import user, wikiutil
from MoinMoin.Page import Page
from MoinMoin.widget import html
from MoinMoin.auth import MoinAuth
def do_register(request):
_ = request.getText
form = request.form
if request.method != 'POST':
return 'missing data'
# TODO : find a cleaner way to get this data
authorized_ips = [
'2a01:240:fe3d:4:2248cff:fe44:3b70', #vo.v6
'2a01:240:fe3d:4:219:bbff:fe3c:4f76', #zamok.v6
]
if request.remote_addr not in authorized_ips:
return 'invalid ip %s' % request.remote_addr
theuser = user.User(request, auth_method="new-user")
try:
theuser.name = form['name']
except KeyError:
return 'missing name'
if not user.isValidName(request, theuser.name):
return 'invalid name'
if user.getUserId(request, theuser.name):
return 'nonunique name'
password = form.get('password', '')
# Encode password
if password and not password.startswith('{SHA}'):
try:
theuser.enc_password = user.encodePassword(password)
except UnicodeError, err:
# Should never happen
return "invalid password %s" % str(err)
# try to get the email, for new users it is required
email = wikiutil.clean_input(form.get('email', ''))
theuser.email = email.strip()
if not theuser.email and 'email' not in request.cfg.user_form_remove:
return 'invalid email'
# Email should be unique - see also MoinMoin/script/accounts/moin_usercheck.py
if theuser.email and request.cfg.user_email_unique:
if user.get_by_email_address(request, theuser.email):
return 'nonunique email'
# save data
try:
theuser.save()
except Exception as err:
return 'error %s' % repr(err)
return 'created'
def execute(pagename, request):
request.write(do_register(request))
......@@ -39,10 +39,9 @@ def send(msg):
smtp.quit()
def creer_compte(nom, mdp, email):
form = {'action': 'newaccount',
form = {'action': 'crans_newaccount',
'name': nom.encode(encoding),
'password1': mdp,
'password2': mdp,
'password': mdp,
'email': email.encode(encoding),
'create_only': 'Create+Profile'}
params = urllib.urlencode(form)
......@@ -53,18 +52,18 @@ def creer_compte(nom, mdp, email):
response = conn.getresponse()
data = response.read()
conn.close()
if 'User account created!' in data:
if 'created' in data:
msg = MIMEText(bugreport.encode(encoding) % form, 'plain', encoding)
msg['Subject'] = "creer_compte_wiki.py: success"
send(msg)
return coul(u"Compte %s cr avec succs !" % nom, "vert")
elif 'This user name already belongs to somebody else.' in data:
elif 'nonunique name' in data:
return coul(u"Le compte %s existe dj !" % nom, "rouge")
elif 'This email already belongs to somebody else.' in data:
elif 'nonunique email' in data:
return coul(u"L'adresse %s est dj utilise !" % email, "rouge")
elif 'Password not acceptable: Password too short.' in data:
return coul(u"Le mot de passe choisi est trop court", "rouge")
elif 'Invalid user name' in data or "Nom d'utilisateur invalide" in data:
elif 'invalid name' in data:
msg = coul(u"Le nom d'utilisateur %s est invalide !" % nom, "rouge")
msg += u"""
Le nom d'utilisateur doit tre un WikiNom, voir ce sujet :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment