Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. class ChangePasswordForm(forms.Form):
  2. old_password = forms.CharField(widget=forms.PasswordInput)
  3. new_password= forms.CharField(widget=forms.PasswordInput)
  4. new_password_again= forms.CharField(widget=forms.PasswordInput)
  5.  
  6. def clean_old_password(self):
  7. data = self.cleaned_data['old_password']
  8. if data != currently_logged_in_user.password:
  9. raise forms.ValidationError("Password Incorrect")
  10.  
  11. return data
  12.  
  13. my_form = ChangePasswordForm(user=request.user, data=request.POST)
  14. ...
  15.  
  16. class ChangePasswordForm(forms.Form):
  17. ...
  18.  
  19. def __init__(self, *args, **kwargs):
  20. self.user = kwargs.pop('user', None)
  21. super(ChangePasswordForm, self).__init__(*args, **kwargs)
  22.  
  23. def clean_old_password(self):
  24. old_password = self.cleaned_data['old_password']
  25. if not self.user.check_password(old_password)
  26. raise forms.ValidationError("Password Incorrect")
  27. return old_password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement