Fix the reset_password_token_created signal to be fired even when no token have been created. #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theDJANGO_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
atNone
instead of aToken
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):
DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE
should indeed control is an error is raised or not, but this should be checked at the view leveldjango_rest_passwordreset.views.ResetPasswordRequestToken.post
django_rest_passwordreset.views.generate_token_for_emai
l to a newutils
module that would also hold the other methods to interact with tokens programmatically.django_rest_passwordreset.views.generate_token_for_email
always raise a custom Exception class when no user is found. This method should have a consistent result when no user is found, that way developers can have theDJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE
setting toTrue
to protect their API, and also know what is wrong when an error occurred while creating programmatically a token. Returning None is not giving enough information on what went wrong, and how to fix it.Checklist