forked from CGM_Public/pretix_original
Fixed #143 -- Password strength validation errors in the right place
This commit is contained in:
@@ -96,18 +96,17 @@ class RegistrationForm(forms.Form):
|
|||||||
password2 = self.cleaned_data.get('password_repeat')
|
password2 = self.cleaned_data.get('password_repeat')
|
||||||
|
|
||||||
if password1 and password1 != password2:
|
if password1 and password1 != password2:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError({
|
||||||
self.error_messages['pw_mismatch'],
|
'password_repeat': self.error_messages['pw_mismatch'],
|
||||||
code='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'))
|
user = User(email=self.cleaned_data.get('email'))
|
||||||
if validate_password(password1, user=user) is not None:
|
if validate_password(password1, user=user) is not None:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid')
|
||||||
_(password_validators_help_texts()),
|
return password1
|
||||||
code='pw_invalid'
|
|
||||||
)
|
|
||||||
return self.cleaned_data
|
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
email = self.cleaned_data['email']
|
email = self.cleaned_data['email']
|
||||||
@@ -142,22 +141,21 @@ class PasswordRecoverForm(forms.Form):
|
|||||||
password2 = self.cleaned_data.get('password_repeat')
|
password2 = self.cleaned_data.get('password_repeat')
|
||||||
|
|
||||||
if password1 and password1 != password2:
|
if password1 and password1 != password2:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError({
|
||||||
self.error_messages['pw_mismatch'],
|
'password_repeat': self.error_messages['pw_mismatch'],
|
||||||
code='pw_mismatch'
|
}, code='pw_mismatch')
|
||||||
)
|
|
||||||
|
|
||||||
|
return self.cleaned_data
|
||||||
|
|
||||||
|
def clean_password(self):
|
||||||
|
password1 = self.cleaned_data.get('password', '')
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(id=self.user_id)
|
user = User.objects.get(id=self.user_id)
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
user = None
|
user = None
|
||||||
if validate_password(password1, user=user) is not None:
|
if validate_password(password1, user=user) is not None:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid')
|
||||||
_(password_validators_help_texts()),
|
return password1
|
||||||
code='pw_invalid'
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.cleaned_data
|
|
||||||
|
|
||||||
|
|
||||||
class PasswordForgotForm(forms.Form):
|
class PasswordForgotForm(forms.Form):
|
||||||
|
|||||||
Reference in New Issue
Block a user