Guest User

Untitled

a guest
Jan 24th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. def save(self, commit=True):
  2. # Save the provided password in hashed format
  3. user = super(RegisterForm, self).save(commit=False)
  4. user.set_password(self.cleaned_data["password"])
  5. if commit:
  6. user.save()
  7. return user
  8.  
  9. class RegisterForm(forms.ModelForm):
  10. email = forms.EmailField()
  11. password = forms.CharField(widget=forms.PasswordInput)
  12. password2 = forms.CharField(label='Confirm Password', widget=forms.PasswordInput)
  13.  
  14. class Meta:
  15. model = User
  16. fields = ('email',)
  17.  
  18. def clean_email(self):
  19. email = self.cleaned_data.get('email')
  20. qs = User.objects.filter(email=email)
  21. if qs.exists():
  22. raise forms.ValidationError("email is taken")
  23. return email
  24.  
  25. def clean_password2(self):
  26. # Check that the two password entries match
  27. password = self.cleaned_data.get("password")
  28. password2 = self.cleaned_data.get("password2")
  29. if password and password2 and password != password2:
  30. raise forms.ValidationError("Passwords don't match")
  31. return password2
  32.  
  33. def save(self, commit=True):
  34. user = super(RegisterForm, self).save(commit=False)
  35. user.set_password(self.cleaned_data['password'])
  36. # user.is_applicant = True
  37. user.is_active = True
  38. if commit:
  39. user.save()
  40. return user
Add Comment
Please, Sign In to add comment