I have the following view for my page to reset your password:
from django.contrib.auth.forms import PasswordChangeForm
def password_change(request):
if request.method == 'POST':
password_form = PasswordChangeForm(data=request.POST, user=request.user)
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user)
messages.add_message(request, messages.SUCCESS, "Password reset.")
return redirect(reverse('elections:home'))
else:
messages.add_message(request, messages.ERROR, "Error with password reset.")
return redirect('/password/new/')
else:
password_form = PasswordChangeForm(user=request.user)
return render(request, 'registration/password_change.html', {
'form': password_form
})
Some of my users are reporting that they are unable to change their password, but it is working for me. As I can't ask them what their password is for obvious reasons, I need a more informative error feedback to the user.
It is my understanding that PasswordChangeForm
generates errors that I can access. Is this true, and if so how do I access these errors in the view to add them to the Django message? If not, how do I create my own form that will return these errors?