diff --git a/main/forms.py b/main/forms.py index 05f770c..622fcae 100644 --- a/main/forms.py +++ b/main/forms.py @@ -1,4 +1,6 @@ from django.contrib.auth.forms import SetPasswordForm +from django.core.validators import MinLengthValidator +from validators import PasswordValidator from models import * @@ -13,6 +15,13 @@ class LDAPSetPasswordForm(SetPasswordForm): self.user.save() return self.user + def clean_new_password1(self): + raw_password = self.cleaned_data.get('new_password1') + # Validation here? + MinLengthValidator(8)(raw_password) + PasswordValidator(raw_passwords) + return raw_password + class LDAPPasswordChangeForm(LDAPSetPasswordForm): pass #old_password = forms.CharField(label=_("Old password"), widget=forms.PasswordInput) diff --git a/main/models.py b/main/models.py index b20fb7d..68ecab0 100644 --- a/main/models.py +++ b/main/models.py @@ -1,8 +1,6 @@ from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField import ldapdb.models import passwd -from django.core.validators import MinLengthValidator -from validators import PasswordValidator class LdapUser(ldapdb.models.Model): """ Class for representing an LDAP user entry. @@ -33,9 +31,6 @@ class LdapUser(ldapdb.models.Model): if raw_password is None: self.password = "!" else: - # Validation here? - MinLengthValidator(8)(raw_password) - PasswordValidator(raw_password) self.password = passwd.ldap_create(raw_password) self.save()