From 81481ba16ea8102f34318ad98d7026f725162e64 Mon Sep 17 00:00:00 2001 From: chirac Date: Thu, 21 Sep 2017 18:47:47 +0200 Subject: [PATCH] =?UTF-8?q?Modifie=20la=20fa=C3=A7on=20dont=20les=20erreur?= =?UTF-8?q?s=20sur=20les=20reinit=20de=20mdp=20sont=20g=C3=A9r=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/forms.py | 7 +++++++ users/models.py | 6 ++++++ users/views.py | 6 +----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/users/forms.py b/users/forms.py index 3fd38560..8eaffd10 100644 --- a/users/forms.py +++ b/users/forms.py @@ -39,6 +39,13 @@ class PassForm(forms.Form): passwd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=255, validators=[MinLengthValidator(8)], widget=forms.PasswordInput) passwd2 = forms.CharField(label=u'Saisir à nouveau le mot de passe', max_length=255, validators=[MinLengthValidator(8)], widget=forms.PasswordInput) + def clean_passwd2(self): + # Check that the two password entries match + password1 = self.cleaned_data.get("passwd1") + password2 = self.cleaned_data.get("passwd2") + if password1 and password2 and password1 != password2: + raise forms.ValidationError("Passwords don't match") + return password2 class UserCreationForm(forms.ModelForm): """A form for creating new users. Includes all the required diff --git a/users/models.py b/users/models.py index 3e3ceb35..a926a236 100644 --- a/users/models.py +++ b/users/models.py @@ -42,6 +42,7 @@ import ldapdb.models.fields from re2o.settings import RIGHTS_LINK, LDAP, GID_RANGES,UID_RANGES import re, uuid import datetime +from re2o.login import hashNT from django.utils import timezone from django.contrib.auth.models import AbstractBaseUser, BaseUserManager @@ -486,6 +487,11 @@ class User(AbstractBaseUser): def all_machines(self): return Interface.objects.filter(machine__in=Machine.objects.filter(user=self)) + def set_user_password(self, password): + self.set_password(password) + self.pwd_ntlm = hashNT(password) + return + def __str__(self): return self.pseudo diff --git a/users/views.py b/users/views.py index 4f795b63..2c6406bf 100644 --- a/users/views.py +++ b/users/views.py @@ -65,11 +65,7 @@ def form(ctx, template, request): def password_change_action(u_form, user, request, req=False): """ Fonction qui effectue le changeemnt de mdp bdd""" - if u_form.cleaned_data['passwd1'] != u_form.cleaned_data['passwd2']: - messages.error(request, "Les 2 mots de passe différent") - return form({'userform': u_form}, 'users/user.html', request) - user.set_password(u_form.cleaned_data['passwd1']) - user.pwd_ntlm = hashNT(u_form.cleaned_data['passwd1']) + user.set_user_password(u_form.cleaned_data['passwd1']) with transaction.atomic(), reversion.create_revision(): user.save() reversion.set_comment("Réinitialisation du mot de passe")