Created
August 31, 2010 11:23
-
-
Save dickbrouwer/558883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailUserCreationForm(UserCreationForm): | |
''' | |
User login form class that replaces the 'username' field with | |
an 'emailfield' on registration, sets email = username in the | |
User object, and adds case-insensitive username verification. | |
''' | |
username = forms.EmailField(label=("Email Address")) | |
confirm = forms.BooleanField(error_messages={'required': | |
'Please read and accept the Terms and Conditions to continue'}) | |
def clean_username(self): | |
username = self.cleaned_data["username"] | |
try: | |
User.objects.get(username__iexact=username) | |
except User.DoesNotExist: | |
return username | |
raise forms.ValidationError(_("A user with that username already exists.")) | |
def save(self, commit=True): | |
user = super(UserCreationForm, self).save(commit=False) | |
user.set_password(self.cleaned_data["password1"]) | |
if commit: | |
user.email = user.username | |
user.save() | |
return user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment