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

Fix the reset_password_token_created signal to be fired even when no token have been created. #188

Closed emickiewicz closed 5 months ago

emickiewicz commented 5 months ago

Bug description

The regression is introduced in V1.4.0 by #181, the the reset_password_token_created.send(...) signal was fired every time when the DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE setting was set to True, even when no user was found and then no reset token created.

When no user was found, the signal was fired with parameter reset_password_token at None instead of a Token object.

Types of changes

Current MR

This MR proposes a fix of the bug and adds more test coverage. The signal is not fired anymore when no token have been created.

Feel free to let me know if you think more tests should be added, or if if you have any other idea on how to improve this fix.

No other existing behavior should be impacted by this fix, so it might be shipped as a minor version as no breaking change is introduced.

Ideas of improvement (with breaking changes) are described bellow.

Note

I think that in order to offer a clear interface for programmatically creating tokens (i.e. without using the DRF API), as the initial MR #181 implemented, we could sightly move the code behavior and approach (not implemented in this MR):

Checklist

nezhar commented 5 months ago

Thanks :100: