Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import newforms as forms
- from users.models import User
- import hashlib
- class UserRegistration(forms.ModelForm):
- email = forms.EmailField()
- passwd = forms.CharField(min_length = 6, widget = forms.PasswordInput)
- confirm_passwd = forms.CharField(widget = forms.PasswordInput)
- class Meta:
- model = User
- fields = ('email', 'passwd')
- def passwd(self):
- passwd = self.cleaned_data.get('passwd', None)
- if not passwd or len(passwd) < 6:
- raise forms.ValidationError('Your password must be at least 6 characters long.')
- passwd = hashlib.sha1(passwd).hexdigest()
- return passwd
- def clean_confirm_passwd(self):
- """Make sure confirmed passwd == passwd"""
- confirm_passwd = hashlib.sha1(self.cleaned_data.get('confirm_passwd', None)).hexdigest()
- if confirm_passwd == self.cleaned_data.get('passwd', ''):
- return confirm_passwd
- raise forms.ValidationError('Your passwords do not match.')
- def clean_email(self):
- """Make sure an e-mail address is unique"""
- email = self.cleaned_data['email']
- try:
- User.objects.get(email = email)
- except (User.DoesNotExist):
- return email
- else:
- raise forms.ValidationError('This email address is already in use.')
Add Comment
Please, Sign In to add comment