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']