Form for registering a new user account.
Validates that the requested username is not already in use, and
requires the password to be entered twice to catch typos.
Subclasses should feel free to add any additional validation they
need, but should avoid defining a ``save()`` method -- the actual
saving of collected user data is delegated to the active
username = forms.RegexField(regex=r'^[\w.@+-]+$',
password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False),
Validate that the username is alphanumeric and is not already
- user = User.objects.get(username
+ user = User.objects.get(username=self.cleaned_data['username'])
raise forms.ValidationError(_("A user with that username already exists."))
match. Note that an error here will end up in
``non_field_errors()`` because it doesn't apply to a single
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
Subclass of ``RegistrationForm`` which adds a required checkbox
for agreeing to a site's Terms of Service.
tos = forms.BooleanField(widget=forms.CheckboxInput(attrs=attrs_dict),
label=_(u'I have read and agree to the Terms of Service'),
Subclass of ``RegistrationForm`` which enforces uniqueness of
Validate that the supplied email address is unique for the
raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
Subclass of ``RegistrationForm`` which disallows registration with
email addresses from popular free webmail services; moderately
useful for preventing automated spam registrations.
To change the list of banned domains, subclass this form and
override the attribute ``bad_domains``.
bad_domains = ['aim.com', 'aol.com', 'email.com', 'gmail.com',
'googlemail.com', 'hotmail.com', 'hushmail.com',
'msn.com', 'mail.ru', 'mailinator.com', 'live.com',
Check the supplied email address against a list of known free
email_domain = self.cleaned_data['email'].split('@')
if email_domain in self.bad_domains: