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

get remaining time for back to login page in DEFENDER_LOCKOUT_TEMPLATE ??? #134

Open
kavehcs opened this issue Aug 28, 2019 · 3 comments
Open

Comments

@kavehcs
Copy link

kavehcs commented Aug 28, 2019

No description provided.

@kencochrane
Copy link
Collaborator

Are you asking how to get the value, or if it is available? I don't think it is currently available, there would need to be a code change to expose that.

@kavehcs
Copy link
Author

kavehcs commented Sep 16, 2019

Are you asking how to get the value, or if it is available? I don't think it is currently available, there would need to be a code change to expose that.

Thanks for your answer , Can you tell me the code to get it؟
I want to show the user the remaining time after reloading the page.

@kencochrane
Copy link
Collaborator

You would need to use the TTL command on Redis to get the Time left for the block for the given Redis key. Either IP or username.

Then you need to add the value to the template context here: https://github.com/kencochrane/django-defender/blob/ce95906488676a44cebd34262426a21303d5dead/defender/utils.py#L293

Which is called in this method here: https://github.com/kencochrane/django-defender/blob/2251c298a9904ad13d69b711ef939dd6b54f84b1/defender/decorators.py#L22
and here
https://github.com/kencochrane/django-defender/blob/2251c298a9904ad13d69b711ef939dd6b54f84b1/defender/decorators.py#L52

currently utils.lockout_response doesn't take that parameter so you would need an update so that it passes in the time left parameter

To keep things simple you could change is_already_locked to return if it is already locked and if so the TTL for the item.

One thing to consider is that someone can be blocked by the IP or the username, so you would need to return the one that has the highest value because they won't be allowed through until both of them are no longer blocking.

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