Open dontic opened 8 months ago
For whoever finds this and needs a solution right now, the current workaround is to use django
's signals.
You won't be able use allauth.account.signals.password_changed(request, user)
or
allauth.account.signals.password_reset(request, user)
because they are not triggered by dj-rest-auth
: https://github.com/iMerica/dj-rest-auth/issues/31
Use this function to trigger a password change notification. It will trigger anytime a password is successfully changed, that being either by the password change or password reset endpoints:
@receiver(pre_save, sender=get_user_model())
def detect_password_change(sender, instance, **kwargs):
"""
Checks if the user changed his password
Cannot use the password_changed signal because it is not triggered
when the user changes his password via dj_rest_auth.
"""
if instance._password is None:
return
try:
user = get_user_model().objects.get(id=instance.id)
except get_user_model().DoesNotExist:
return
print("password changed")
And send an email manually using this.
django-allauth
introducedACCOUNT_EMAIL_NOTIFICATIONS
this past February:https://docs.allauth.org/en/latest/release-notes/recent.html
In
django-allauth
this is handled in their views.For instance, in
PasswordChangeView
:I believe this is why it's not triggered in
dj-rest-auth
:Possible solution:
Add
send_notification_mail
fromdjango-allauth
to thePasswordResetConfirmSerializer
andPasswordChangeSerializer
views ifACCOUNT_EMAIL_NOTIFICATIONS
isTrue