class EditPasswordForm forms Form old_password forms CharField max_len

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class EditPasswordForm(forms.Form):
old_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
new_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
new_password_confirmation = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
def clean(self):
if not check_password(request.user, self.cleaned_data['old_password']):
raise forms.ValidationError(u"Old password isnt correct")
if self.cleaned_data['new_password'] != self.cleaned_data['new_password_confirmation']:
raise forms.ValidationError(u"password didnt match")
return self.cleaned_data