class EditPasswordForm forms Form old_password forms CharField max_len

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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 __init__(self, request, *args, **kwargs):
self.request = request
super(EditPasswordForm, self).__init__(*args, **kwargs)
def clean_old_password(self):
if not self.request.user.check_password(self.cleaned_data['old_password']):
raise forms.ValidationError(u"Old password isn't correct")
return self.cleaned_data['old_password']
def clean_new_password_confirmation(self):
if self.cleaned_data['new_password'] != self.cleaned_data['new_password_confirmation']:
raise forms.ValidationError(u"password didnt match")
return self.cleaned_data['new_password_confirmation']