Commit d0edf08f authored by Gabriel Detraz's avatar Gabriel Detraz

Change mdp sur une page séparée

parent a19f67ab
......@@ -12,7 +12,10 @@ class CompteForm(forms.Form):
annetudes = forms.IntegerField(label=u"Année d'étude", max_value=9)
dometudes = forms.CharField(label=u'Domaine', max_length=10)
newalias = forms.EmailField(label=u'Nouveau alias Mail', max_length=20, required=False)
greylist = forms.CharField(label=u'GreyList', max_length=10, widget= widgets.CheckboxInput, required=False)
class PassForm(forms.Form):
passwdexists = forms.CharField(label=u'Ancien mot de passe', max_length=10, widget= widgets.PasswordInput, required=False)
newpasswd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=10, widget= widgets.PasswordInput, required=False)
newpasswd2 = forms.CharField(label=u'Nouveau mot de passe', max_length=10, widget= widgets.PasswordInput, required=False)
greylist = forms.CharField(label=u'GreyList', max_length=10, widget= widgets.CheckboxInput, required=False)
......@@ -3,7 +3,7 @@ from django.conf.urls import url
import views
urlpatterns = patterns('',
url('^$', views.afficher, name='afficher')
url('^$', views.afficher, name='afficher'),
url('chgpass', views.chgpass, name='chgpass')
)
......@@ -17,6 +17,7 @@ from gestion.chgpass import check_password
import lc_ldap.crans_utils
from forms import CompteForm
from forms import PassForm
from django.forms.util import ErrorList
# Vue d'affichage seulement des infos pour l'adh
......@@ -93,6 +94,28 @@ def afficher(request):
errors = form._errors.setdefault("newalias", ErrorList())
errors.append(u"L'alias doit avoir @crans.org pour suffixe")
# Checkbox grey_list : rien de spécial ici
if form.cleaned_data['greylist']=="on":
luser["contourneGreylist"] = "OK"
elif form.cleaned_data['greylist']=="False":
luser["contourneGreylist"] = []
# On génère l'historique et on enregistre
luser.history_gen()
luser.save()
else:
form = CompteForm(initial={'nom': luser['nom'][0], 'prenom': luser['prenom'][0],'tel': luser['tel'][0],'greylist': gl, 'annetudes': luser['etudes'][1], 'etabetudes': luser['etudes'][0], 'annetudes': luser['etudes'][1], 'dometudes': luser['etudes'][2]})
return django.shortcuts.render_to_response("compte/affichage.html", locals(), context_instance=RequestContext(request))
@login_required
def chgpass(request):
if request.method == "POST":
form = PassForm(request.POST)
if form.is_valid():
luserconn = conn_pool.get_user(request.user, mode='w')
with luserconn as luser:
# Changement de mot de passe : il faut satisfaire à : le mot de passe existant est le bon, les 2 champs nouveaux mot de passe sont égaux,
# , et le nouveau mot de passe respete la convention Cr@ns. Si non, on renvoie une erreur à chaque fois.
if "passwdexists" in form.changed_data:
......@@ -113,18 +136,9 @@ def afficher(request):
errors = form._errors.setdefault("passwdexists", ErrorList())
errors.append(u"Le mot de passe existant n'est pas bon")
# Checkbox grey_list : rien de spécial ici
if form.cleaned_data['greylist']=="on":
luser["contourneGreylist"] = "OK"
elif form.cleaned_data['greylist']=="False":
luser["contourneGreylist"] = []
# On génère l'historique et on enregistre
luser.history_gen()
luser.save()
else:
form = CompteForm(initial={'nom': luser['nom'][0], 'prenom': luser['prenom'][0],'tel': luser['tel'][0],'greylist': gl, 'annetudes': luser['etudes'][1], 'etabetudes': luser['etudes'][0], 'annetudes': luser['etudes'][1], 'dometudes': luser['etudes'][2]})
return django.shortcuts.render_to_response("compte/affichage.html", locals(), context_instance=RequestContext(request))
else:
form = PassForm()
return django.shortcuts.render_to_response("compte/chgpass.html", locals(), context_instance=RequestContext(request))
......@@ -24,10 +24,10 @@
<tr><td>{{ form.newalias.label_tag }}: {{ form.newalias }} {{ form.newalias.errors }}</tr></td>
<td>Afin d'éviter les abus, la destruction d'un alias nécessite une demande via la mailing-list respbats@crans.org</td>
<tr><td>{{ form.greylist.label_tag }}: {{ form.greylist }}</tr></td>
<tr><td>{{ form.passwdexists.label_tag }}: {{ form.passwdexists }} {{ form.passwdexists.errors }}</tr></td>
<tr><td>{{ form.newpasswd1.label_tag }}: {{ form.newpasswd1 }}</tr></td>
<tr><td>{{ form.newpasswd2.label_tag }}: {{ form.newpasswd2 }} {{ form.newpasswd2.errors }}</tr></td>
<tr><td><input type="submit" value="Enregistrer"></tr></td>
<tr><td><input type="submit" value="Enregistrer les changements"></tr></td>
</form>
<tr><td><form action="/compte/chgpass">
<input type="submit" value="Changer mon mot de passe Cr@ns">
</form></tr></td>
</table>
{% endblock %}
{% extends "template.html" %}
{% block title %} Mot de passe {% endblock %}
{% block content %}
<table>
<form action="/compte/chgpass/" method="post">
{% csrf_token %}
<tr><td>{{ form.passwdexists.label_tag }}: {{ form.passwdexists }} {{ form.passwdexists.errors }}</tr></td>
<tr><td>{{ form.newpasswd1.label_tag }}: {{ form.newpasswd1 }}</tr></td>
<tr><td>{{ form.newpasswd2.label_tag }}: {{ form.newpasswd2 }} {{ form.newpasswd2.errors }}</tr></td>
<tr><td><input type="submit" value="Enregistrer"></tr></td>
</form>
</table>
{% endblock %}
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