def form_valid(self, form):
user = self.request.user
if not check_password(self.request.POST['oldpassword'], user.password):
return JsonResponse({
'error': True,
'response': {'oldpassword': 'Invalid old password'}
})
if self.request.POST['newpassword'] != self.request.POST['retypepassword']:
return JsonResponse({
'error': True,
'response': {'newpassword': 'New password and Confirm Passwords did not match'}
})
user.set_password(self.request.POST['newpassword'])
user.save()
return JsonResponse({'error': False, 'message': 'Password changed successfully'})
评论列表
文章目录