Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing login_valid with False on successful custom login #200

Open
ashrafemad opened this issue Jan 13, 2022 · 1 comment
Open

Storing login_valid with False on successful custom login #200

ashrafemad opened this issue Jan 13, 2022 · 1 comment

Comments

@ashrafemad
Copy link

I've added watch_login() decorator to my custom login class and i saw it always storing login_valid on db as False

i found that my view returns status_code 200 and not 302 so i added status_code argument to watch_login(status_code=200) and it's still login_valid is False

Looking at the package source code i found this defender/decorators.py

if status_code == 302:  # standard Django login view
    login_unsuccessful = (
        response
        and not response.has_header("location")
        and response.status_code != status_code
    )
else:
    # If msg is not passed the last condition will be evaluated
    # always to True so the first 2 will decide the result.
    login_unsuccessful = (
        response
        and response.status_code == status_code
        and msg in response.content.decode("utf-8")
    )

i think in the else block we need to change and response.status_code == status_code to be and response.status_code != status_code

@kencochrane
Copy link
Collaborator

@ashrafemad thanks for finding this. It has been a while since I looked at that code, but I think you are right. Feel free to submit a PR with the proposed change, and we can review and merge. If possible, maybe add a unit test to confirm it is working as it should, and we make sure we don't regress in the future. Thanks again.

ashrafemad pushed a commit to ashrafemad/django-defender that referenced this issue Jan 18, 2022
ashrafemad added a commit to ashrafemad/django-defender that referenced this issue Jan 24, 2022
issue jazzband#200 fix successful login should not add failure attempt or blo…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants