From 09e5c43c55b2d231af8066e326b5aef564f21881 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 10 Jun 2016 15:33:32 +0200 Subject: [PATCH] Fixed #143 -- Password strength validation errors in the right place --- src/pretix/base/forms/auth.py | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/pretix/base/forms/auth.py b/src/pretix/base/forms/auth.py index a83dcac963..70d38a97be 100644 --- a/src/pretix/base/forms/auth.py +++ b/src/pretix/base/forms/auth.py @@ -96,18 +96,17 @@ class RegistrationForm(forms.Form): password2 = self.cleaned_data.get('password_repeat') if password1 and password1 != password2: - raise forms.ValidationError( - self.error_messages['pw_mismatch'], - code='pw_mismatch' - ) + raise forms.ValidationError({ + 'password_repeat': self.error_messages['pw_mismatch'], + }, code='pw_mismatch') + return self.cleaned_data + def clean_password(self): + password1 = self.cleaned_data.get('password', '') user = User(email=self.cleaned_data.get('email')) if validate_password(password1, user=user) is not None: - raise forms.ValidationError( - _(password_validators_help_texts()), - code='pw_invalid' - ) - return self.cleaned_data + raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid') + return password1 def clean_email(self): email = self.cleaned_data['email'] @@ -142,22 +141,21 @@ class PasswordRecoverForm(forms.Form): password2 = self.cleaned_data.get('password_repeat') if password1 and password1 != password2: - raise forms.ValidationError( - self.error_messages['pw_mismatch'], - code='pw_mismatch' - ) + raise forms.ValidationError({ + 'password_repeat': self.error_messages['pw_mismatch'], + }, code='pw_mismatch') + return self.cleaned_data + + def clean_password(self): + password1 = self.cleaned_data.get('password', '') try: user = User.objects.get(id=self.user_id) except User.DoesNotExist: user = None if validate_password(password1, user=user) is not None: - raise forms.ValidationError( - _(password_validators_help_texts()), - code='pw_invalid' - ) - - return self.cleaned_data + raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid') + return password1 class PasswordForgotForm(forms.Form):