From 8bb8241ae2df9295e35611562d5452e95851b648 Mon Sep 17 00:00:00 2001 From: Quang Date: Tue, 5 Aug 2014 13:48:47 -0700 Subject: [PATCH] allow cross-domain cookie --- README.rst | 6 ++++++ django_mobile/__init__.py | 1 + django_mobile/conf.py | 1 + 3 files changed, 8 insertions(+) diff --git a/README.rst b/README.rst index 086be04..042864d 100644 --- a/README.rst +++ b/README.rst @@ -250,6 +250,12 @@ changed in your own ``settings.py``: **Default:** ``False`` +``FLAVOURS_COOKIE_DOMAIN`` + The value that get passed into ``HttpResponse.set_cookie``'s ``domain`` + argument. Set this to ``.yourdomain.com`` if you want to use cross-domain cookie which is readable by its domain and its subdomains, e.g. sub.yourdomain.com. Otherwise, it's only readable by its domain. + + **Default:** ``None`` + ``FLAVOURS_COOKIE_KEY`` The cookie name that is used for storing the selected flavour in the browser. This is only used if ``FLAVOURS_STORAGE_BACKEND`` is set to diff --git a/django_mobile/__init__.py b/django_mobile/__init__.py index 8631b9f..8945067 100644 --- a/django_mobile/__init__.py +++ b/django_mobile/__init__.py @@ -37,6 +37,7 @@ def save(self, request, response): response.set_cookie( smart_str(settings.FLAVOURS_COOKIE_KEY), smart_str(request._flavour_cookie), + domain=settings.FLAVOURS_COOKIE_DOMAIN, httponly=settings.FLAVOURS_COOKIE_HTTPONLY) diff --git a/django_mobile/conf.py b/django_mobile/conf.py index 3ffc804..1547eab 100644 --- a/django_mobile/conf.py +++ b/django_mobile/conf.py @@ -27,6 +27,7 @@ class defaults(object): FLAVOURS_GET_PARAMETER = u'flavour' FLAVOURS_STORAGE_BACKEND = u'cookie' FLAVOURS_COOKIE_KEY = u'flavour' + FLAVOURS_COOKIE_DOMAIN = None FLAVOURS_COOKIE_HTTPONLY = False FLAVOURS_SESSION_KEY = u'flavour' FLAVOURS_TEMPLATE_LOADERS = []