Lors du changement d'un mot de passe chercheur, on change AuthLDAP
authorPA Parent <paparent@paparent.me>
Wed, 5 Oct 2011 17:37:34 +0000 (13:37 -0400)
committerPA Parent <paparent@paparent.me>
Wed, 5 Oct 2011 17:37:34 +0000 (13:37 -0400)
auf_savoirs_en_partage/chercheurs/views.py
auf_savoirs_en_partage/urls.py

index 5ffb6e1..ace0564 100644 (file)
@@ -20,6 +20,8 @@ from django.utils.http import int_to_base36, base36_to_int
 from django.views.decorators.cache import never_cache
 from django.contrib.auth import authenticate
 from django.shortcuts import get_object_or_404
+from django.views.decorators.csrf import csrf_protect
+from django.contrib.auth.forms import PasswordChangeForm
 from savoirs.models import PageStatique, Discipline
 
 
@@ -103,6 +105,33 @@ def activation(request, id_base36, token):
     return render_to_response('chercheurs/activation.html', dict(form=form, validlink=validlink),
                               context_instance=RequestContext(request))
 
+@csrf_protect
+@login_required
+def password_change(request, template_name='registration/password_change_form.html',
+                    post_change_redirect=None, password_change_form=PasswordChangeForm):
+    if post_change_redirect is None:
+        post_change_redirect = url('django.contrib.auth.views.password_change_done')
+    if request.method == "POST":
+        form = password_change_form(user=request.user, data=request.POST)
+        if form.is_valid():
+            form.save()
+
+            # Mot de passe pour LDAP
+            username = request.user.email
+            authldap, created = AuthLDAP.objects.get_or_create(username=username)
+            password = form.cleaned_data.get('new_password1')
+            ldap_hash = create_ldap_hash(password)
+            authldap.ldap_hash = ldap_hash
+            authldap.save()
+
+            return HttpResponseRedirect(post_change_redirect)
+    else:
+        form = password_change_form(user=request.user)
+    return render_to_response(template_name, {
+        'form': form,
+    }, context_instance=RequestContext(request))
+
+
 @chercheur_required
 def desinscription(request):
     """Désinscription du chercheur"""
index 526edce..7cf65c7 100644 (file)
@@ -79,7 +79,7 @@ urlpatterns = sep_patterns + patterns(
     (r'^chercheurs/deconnexion/$', 'django.contrib.auth.views.logout', dict(
         template_name='chercheurs/logged_out.html'
     ), 'chercheurs-logout'),
-    (r'^chercheurs/changement-mdp/$', 'django.contrib.auth.views.password_change', dict(
+    (r'^chercheurs/changement-mdp/$', 'chercheurs.views.password_change', dict(
         template_name='chercheurs/password_change_form.html',
         post_change_redirect='/chercheurs/changement-mdp-fini/'
     ), 'chercheurs-password-change'),