[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.
This commit is contained in:
parent
0b22dda0c2
commit
447d028dc8
2 changed files with 79 additions and 7 deletions
73
wiki/action/crans_newaccount.py
Normal file
73
wiki/action/crans_newaccount.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
# -*- 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()
|
smtp.quit()
|
||||||
|
|
||||||
def creer_compte(nom, mdp, email):
|
def creer_compte(nom, mdp, email):
|
||||||
form = {'action': 'newaccount',
|
form = {'action': 'crans_newaccount',
|
||||||
'name': nom.encode(encoding),
|
'name': nom.encode(encoding),
|
||||||
'password1': mdp,
|
'password': mdp,
|
||||||
'password2': mdp,
|
|
||||||
'email': email.encode(encoding),
|
'email': email.encode(encoding),
|
||||||
'create_only': 'Create+Profile'}
|
'create_only': 'Create+Profile'}
|
||||||
params = urllib.urlencode(form)
|
params = urllib.urlencode(form)
|
||||||
|
@ -53,18 +52,18 @@ def creer_compte(nom, mdp, email):
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
data = response.read()
|
data = response.read()
|
||||||
conn.close()
|
conn.close()
|
||||||
if 'User account created!' in data:
|
if 'created' in data:
|
||||||
msg = MIMEText(bugreport.encode(encoding) % form, 'plain', encoding)
|
msg = MIMEText(bugreport.encode(encoding) % form, 'plain', encoding)
|
||||||
msg['Subject'] = "creer_compte_wiki.py: success"
|
msg['Subject'] = "creer_compte_wiki.py: success"
|
||||||
send(msg)
|
send(msg)
|
||||||
return coul(u"Compte %s créé avec succès !" % nom, "vert")
|
return coul(u"Compte %s créé avec succès !" % 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 déjà !" % nom, "rouge")
|
return coul(u"Le compte %s existe déjà !" % nom, "rouge")
|
||||||
elif 'This email already belongs to somebody else.' in data:
|
elif 'nonunique email' in data:
|
||||||
return coul(u"L'adresse %s est déjà utilisée !" % email, "rouge")
|
return coul(u"L'adresse %s est déjà utilisée !" % email, "rouge")
|
||||||
elif 'Password not acceptable: Password too short.' in data:
|
elif 'Password not acceptable: Password too short.' in data:
|
||||||
return coul(u"Le mot de passe choisi est trop court", "rouge")
|
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 = coul(u"Le nom d'utilisateur %s est invalide !" % nom, "rouge")
|
||||||
msg += u"""
|
msg += u"""
|
||||||
Le nom d'utilisateur doit être un WikiNom, voir à ce sujet :
|
Le nom d'utilisateur doit être un WikiNom, voir à ce sujet :
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue