Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserCreationMixin(forms.ModelForm):
- error_messages = {
- 'password-mismatch': _(u'Enter the same password as before')
- }
- first_name = forms.CharField(
- label=_(u'First Name'),
- max_length=100,
- help_text=_(u'Enter your first name')
- ),
- last_name = forms.CharField(
- label=_(u'Last Name'),
- max_length=100,
- help_text=_(u'Enter your last name')
- ),
- username = forms.CharField(
- label=_(u'Username'),
- min_length=8,
- max_length=30,
- help_text=_(u'Enter a valid username')
- )
- email = forms.EmailField(
- label=_(u'Email Address'),
- help_text=_(u'Enter a valid email address')
- ),
- password = forms.CharField(
- label=_(u'Password'),
- widget=forms.PasswordInput,
- help_text=_(u'Enter a valid password')
- ),
- confirm_password = forms.CharField(
- label=_(u'Confirm Password'),
- widget=forms.PasswordInput,
- help_text=_(u'Confirm your passwords match')
- )
- def clean_confirm_password(self):
- password = self.cleaned_data['password']
- password2 = self.cleaned_data['confirm_password']
- if password and password2 and password != password2:
- raise forms.ValidationError(
- UserCreationMixin.error_messages['password-mismatch'],
- code='password_mismatch'
- )
- return password2
- self.instance.username = self.cleaned_data['username']
- password_validation.validate_password(password2, self.instance)
- return password2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement