I have a ChangePasswordView for my User:
class ChangePasswordView(PasswordChangeView):
form_class = ChangePasswordForm
success_url = reverse_lazy('password_success')
#success view
def password_success(request):
return render(request, 'accounts/password_success.html')
I've been using the send_mail
function to notify Users when they update their information, however, in this case, I'm having some trouble.
I added this to my ChangePasswordView:
def form_valid(self, form):
form.update_password_email()
return redirect(self.success_url)
And this to my ChangePasswordForm:
def update_password_email(self):
email = self.cleaned_data.get('email', None)
if email and self.is_valid():
send_mail(
'Password changed',
'Message',
NOTIFICATION_EMAIL,
[self.cleaned_data['email']],
fail_silently=True
)
But it doesn't work. I go to django's change password page, enter my old password, new password and confirm it, but the logic isn't running. Instead I get redirected to my success_url
with no password change and no email notification.
Is the issue happening because of my view or my form? And what issue is happening.
Also do I need form_valid():
and if self.is_valid():
or is one of those extra? I assume they're doing the same thing.