Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ChangePasswordForm(forms.Form):
- old_password = forms.CharField(widget=forms.PasswordInput)
- new_password= forms.CharField(widget=forms.PasswordInput)
- new_password_again= forms.CharField(widget=forms.PasswordInput)
- def clean_old_password(self):
- data = self.cleaned_data['old_password']
- if data != currently_logged_in_user.password:
- raise forms.ValidationError("Password Incorrect")
- return data
- my_form = ChangePasswordForm(user=request.user, data=request.POST)
- ...
- class ChangePasswordForm(forms.Form):
- ...
- def __init__(self, *args, **kwargs):
- self.user = kwargs.pop('user', None)
- super(ChangePasswordForm, self).__init__(*args, **kwargs)
- def clean_old_password(self):
- old_password = self.cleaned_data['old_password']
- if not self.user.check_password(old_password)
- raise forms.ValidationError("Password Incorrect")
- return old_password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement