Fix #1159: Fallback to USERNAME_FIELD when AXES_USERNAME_FORM_FIELD not in credentials#1414
Open
Dzhud wants to merge 2 commits intojazzband:masterfrom
Open
Fix #1159: Fallback to USERNAME_FIELD when AXES_USERNAME_FORM_FIELD not in credentials#1414Dzhud wants to merge 2 commits intojazzband:masterfrom
Dzhud wants to merge 2 commits intojazzband:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #1159: Fallback to USERNAME_FIELD when AXES_USERNAME_FORM_FIELD not in credentials
Summary
When
AXES_USERNAME_FORM_FIELDis set to a custom value (e.g.,"auth-username"), theAccessAttemptrecord wasn't getting the username populated because Django'suser_login_failedsignal sends credentials usingUSERNAME_FIELD(typically"username"), not the custom field name.Changes
get_client_username()inaxes/helpers.pyto add fallback logic:AXES_USERNAME_FORM_FIELDget_user_model().USERNAME_FIELDif not founddocs/4_configuration.rstto describe the fallback behaviorHow it works
Tests
Wrote 3 new tests to cover this fix:
test_get_client_username_fallback_to_username_field_from_credentialsUSERNAME_FIELDtest_get_client_username_fallback_to_username_field_from_requestrequest.POSTdatatest_get_client_username_custom_field_takes_priorityVerification
Fixes #1159