mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge pull request #1236 from modoboa/fix/display_validation_errors
Fixed validation errors display.
This commit is contained in:
@@ -183,14 +183,18 @@ class AccountFormGeneral(forms.ModelForm):
|
||||
self.add_error("password1", _("This field is required."))
|
||||
if not password2:
|
||||
self.add_error("password2", _("This field is required."))
|
||||
if not self.errors:
|
||||
if password1 != password2:
|
||||
self.add_error(
|
||||
"password2",
|
||||
_("The two password fields didn't match."))
|
||||
else:
|
||||
password_validation.validate_password(
|
||||
password2, self.instance)
|
||||
if self.errors:
|
||||
return self.cleaned_data
|
||||
if password1 != password2:
|
||||
self.add_error(
|
||||
"password2",
|
||||
_("The two password fields didn't match."))
|
||||
return self.cleaned_data
|
||||
try:
|
||||
password_validation.validate_password(
|
||||
password2, self.instance)
|
||||
except forms.ValidationError as ve:
|
||||
self.add_error("password2", ve.messages)
|
||||
return self.cleaned_data
|
||||
|
||||
def save(self, commit=True):
|
||||
|
||||
@@ -128,6 +128,13 @@ class AccountTestCase(ModoTestCase):
|
||||
resp["form_errors"]["password2"][0],
|
||||
"The two password fields didn't match.")
|
||||
|
||||
values["password1"] = "toto1234"
|
||||
values["password2"] = "toto1234"
|
||||
resp = self.ajax_post(reverse("admin:account_add"), values, 400)
|
||||
self.assertEqual(
|
||||
resp["form_errors"]["password2"][0],
|
||||
"Password must contain at least 1 uppercase letter.")
|
||||
|
||||
def test_random_password(self):
|
||||
"""Try to create an account with a random password."""
|
||||
values = {
|
||||
|
||||
Reference in New Issue
Block a user