Last active
November 25, 2016 12:11
-
-
Save agusmakmun/09f17c2162c27a3fcc9a10fbe446b56e to your computer and use it in GitHub Desktop.
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
# From: http://django-admin-honeypot.readthedocs.io/en/latest/manual/faq.html#why-is-the-ip-address-logged-as-127-0-0-1 | |
class RemoteAddrMiddleware(object): | |
def process_request(self, request): | |
if 'HTTP_X_FORWARDED_FOR' in request.META: | |
ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip() | |
request.META['REMOTE_ADDR'] = ip |
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
# force all conditions | |
# https://github.com/dmpayton/django-admin-honeypot/issues/6#issue-13552309 | |
redirect_conditions = [ | |
request.user.is_authenticated(), | |
request.user.is_active, | |
request.user.is_staff, | |
] | |
if all(redirect_conditions): | |
return redirect(somewhere_else) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment