anexia-it / django-rest-passwordreset

An extension of django rest framework, providing a configurable password reset strategy
BSD 3-Clause "New" or "Revised" License
419 stars 148 forks source link

[BUG] two tokens get created #150

Closed mathijsfr closed 2 years ago

mathijsfr commented 2 years ago

Whenever I post an api call with an email to http://127.0.0.1:8000/api/password_reset/, the following code is run twice:

@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):

    email_plaintext_message = "{}?token={}".format(reverse('password_reset:reset-password-request'), reset_password_token.key)
    print(reset_password_token.key)
    send_mail(
        # title:
        "Password Reset for {title}".format(title="Some website title"),
        # message:
        email_plaintext_message,
        # from:
        '[example@example.com]',
        # to:
        [reset_password_token.user.email],
        fail_silently=False
    )

This sends two e-mails to my mail with two different tokens. Each time, only one of the tokens work. For example:

9ae5ad217f6edf91185d609 and 35ac9fd6e439b3

in two separate emails.

What do I do to only send 1 e-mail each time with the correct token?

mathijsfr commented 2 years ago

Found the problem. Two seperate accounts can't have the same e-mail. An e-mail is send for each user having the requested e-mail, which I realize is to be expected.