Skip to content

Commit

Permalink
Adding setting for IP Address header.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyface committed Mar 30, 2019
1 parent 06f8efb commit 40ece1a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ Configuration
=============

Configuration is minimal for termsandconditions itself, A quick guide to a basic setup
is below, take a look at the demo app for more details.
is below, take a look at the demo app's settings.py for more details.

Some useful settings:
* `TERMS_IP_HEADER_NAME` Name of header to check for IP address. Defaults to 'REMOTE_ADDR'. You might need to use 'HTTP_X_FORWARDED_FOR', or other headers in proxy setups.
* `TERMS_STORE_IP_ADDRESS` - True/False whether to store IPs with Terms Acceptance

Requirements
------------
Expand Down Expand Up @@ -153,7 +157,7 @@ explicit full paths to exclude. TERMS_EXCLUDE_URL_CONTAINS_LIST is a list of url

You can also define a setting TERMS_EXCLUDE_USERS_WITH_PERM to exclude users with a custom permission you create yourself.::

TERMS_EXCLUDE_USERS_WITH_PERM 'MyModel.can_skip_terms'
TERMS_EXCLUDE_USERS_WITH_PERM = 'MyModel.can_skip_terms'

This can be useful if you need to run continuous login integration tests or simply exclude specific users from having to accept your T&Cs.
Note that we exclude superusers from this check due to Django's has_perm() method returning True for any permission check, so adding this
Expand Down
3 changes: 2 additions & 1 deletion termsandconditions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

LOGGER = logging.getLogger(name='termsandconditions')
DEFAULT_TERMS_BASE_TEMPLATE = 'base.html'
DEFAULT_TERMS_IP_HEADER_NAME = 'REMOTE_ADDR'


class GetTermsViewMixin(object):
Expand Down Expand Up @@ -114,7 +115,7 @@ def post(self, request, *args, **kwargs):

store_ip_address = getattr(settings, 'TERMS_STORE_IP_ADDRESS', True)
if store_ip_address:
ip_address = request.META['REMOTE_ADDR']
ip_address = request.META.get(getattr(settings, 'TERMS_IP_HEADER_NAME', DEFAULT_TERMS_IP_HEADER_NAME))
else:
ip_address = ""

Expand Down
25 changes: 13 additions & 12 deletions termsandconditions_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Cache Settings
CACHES = {
'default': {
#'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
# 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
Expand Down Expand Up @@ -63,15 +63,15 @@
# DB settings
if os.environ.get('TERMS_DATABASE', "sqlite") == 'postgresql':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'termsandconditions',
'USER': 'termsandconditions',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '', # Set to empty string for default.
'SUPPORTS_TRANSACTIONS': 'true',
},
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'termsandconditions',
'USER': 'termsandconditions',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '', # Set to empty string for default.
'SUPPORTS_TRANSACTIONS': 'true',
},
}
else:
DATABASES = {
Expand Down Expand Up @@ -189,7 +189,6 @@
# For use Pre Django 1.10
MIDDLEWARE_CLASSES = MIDDLEWARE


ROOT_URLCONF = 'termsandconditions_demo.urls'

INSTALLED_APPS = (
Expand All @@ -214,7 +213,9 @@
TERMS_EXCLUDE_URL_LIST = {'/', '/termsrequired/', '/logout/', '/securetoo/'}
TERMS_EXCLUDE_URL_CONTAINS_LIST = {} # Useful if you are using internationalization and your URLs could change per language
TERMS_CACHE_SECONDS = 30
TERMS_EXCLUDE_USERS_WITH_PERM='auth.can_skip_t&c'
TERMS_EXCLUDE_USERS_WITH_PERM = 'auth.can_skip_t&c'
TERMS_IP_HEADER_NAME = 'REMOTE_ADDR'
TERMS_STORE_IP_ADDRESS = True

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

Expand Down

0 comments on commit 40ece1a

Please sign in to comment.