This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
neuf-userinfo/main/forms.py
T
nikolark 6d6a4a0a13 Switches to twitter bootstrap styling
- jQuery 1.7.1
 - Replaces jquery-qtip with bootstrap alternative
 - Responsive design
 - Misc fixes
2012-02-12 03:49:11 +01:00

47 lines
1.6 KiB
Python

from django.contrib.auth.forms import SetPasswordForm, PasswordResetForm
from django.core.validators import MinLengthValidator
from django import forms
from django.utils.translation import ugettext as _
from models import *
from validators import PasswordValidator
import utils
class LDAPSetPasswordForm(SetPasswordForm):
def save(self, commit=True):
# set kerberos password
set_krb5 = utils.set_kerberos_password(self.user.username, self.cleaned_data['new_password1'])
# set radius password
set_radius = utils.set_radius_password(self.user.username, self.cleaned_data['new_password1'])
# Lookup the Ldap user with the identical username (1-to-1).
self.user = LdapUser.objects.get(username=self.user.username)
self.user.set_password(self.cleaned_data['new_password1'])
if commit:
self.user.save()
# TODO: Log the result of the above.
return self.user
def clean_new_password1(self):
raw_password = self.cleaned_data.get('new_password1')
# Validation here?
MinLengthValidator(8)(raw_password)
PasswordValidator(raw_password)
return raw_password
class LDAPPasswordChangeForm(LDAPSetPasswordForm):
pass
class LDAPPasswordResetForm(PasswordResetForm):
def clean_email(self):
email = self.cleaned_data["email"].lower()
self.users_cache = LdapUser.objects.filter(email=email)
if len(self.users_cache) == 0:
raise forms.ValidationError(_("That e-mail address doesn't have an associated user account. Are you sure you've registered?"))
return email