Created
November 26, 2011 17:34
-
-
Save hsparikh/1396014 to your computer and use it in GitHub Desktop.
django-userena
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 SignupForm(forms.Form): | |
""" | |
Form for creating a new user account. | |
Validates that the requested username and e-mail is not already in use. | |
Also requires the password to be entered twice and the Terms of Service to | |
be accepted. | |
""" | |
username = forms.RegexField(regex=USERNAME_RE, | |
max_length=30, | |
widget=forms.TextInput(attrs=attrs_dict), | |
label=_("Username"), | |
error_messages={'invalid': _('Username must contain only letters, numbers, dots and underscores.')}) | |
# Add first name and last name fields to the signup form | |
first_name = forms.CharField(widget=forms.TextInput(attrs=attrs_dict), | |
label=_("First name"), | |
) | |
last_name = forms.CharField(widget=forms.TextInput(attrs=attrs_dict), | |
label=_("Last name"), | |
) | |
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, | |
maxlength=75)), | |
label=_("Email")) | |
password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, | |
render_value=False), | |
label=_("Create password")) | |
password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, | |
render_value=False), | |
label=_("Repeat password")) | |
... | |
def save(self, force_insert=False, force_update=False, commit=True): | |
""" Creates a new user and account. Returns the newly created user. """ | |
username, email, password = (self.cleaned_data['username'], | |
self.cleaned_data['email'], | |
self.cleaned_data['password1']) | |
new_user = UserenaSignup.objects.create_user(username, | |
email, | |
password, | |
not userena_settings.USERENA_ACTIVATION_REQUIRED, | |
userena_settings.USERENA_ACTIVATION_REQUIRED) | |
account = super(SignupForm, self).save(commit=commit) | |
# Save first and last name | |
new_user = account.user | |
new_user.first_name = self.cleaned_data['first_name'] | |
new_user.last_name = self.cleaned_data['last_name'] | |
new_user.save() | |
return new_user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment