diff --git a/taccsite_cms/custom_app_settings.example.py b/taccsite_cms/custom_app_settings.example.py index 3ac04c50d..46ab65ef9 100644 --- a/taccsite_cms/custom_app_settings.example.py +++ b/taccsite_cms/custom_app_settings.example.py @@ -1,3 +1,3 @@ CUSTOM_APPS = ['apps.custom_example'] -CUSTOM_MIDDLEWARE = [] +CUSTOM_MIDDLEWARE = ['taccsite_cms.middleware.settings.SiteIdMiddleware'] STATICFILES_DIRS = () diff --git a/taccsite_cms/middleware/settings.py b/taccsite_cms/middleware/settings.py new file mode 100644 index 000000000..0c2f3ff14 --- /dev/null +++ b/taccsite_cms/middleware/settings.py @@ -0,0 +1,20 @@ +"""Change site based on domain name (fallback to default site)""" +from django.conf import settings +from urllib.parse import urlparse +from django.contrib.sites.models import Site + +class SiteIdMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + try: + current_site = Site.objects.get(domain=request.get_host()) + except Site.DoesNotExist: + current_site = Site.objects.get(id=settings.DEFAULT_SITE_ID) + + request.current_site = current_site + settings.SITE_ID = current_site.id + + response = self.get_response(request) + return response diff --git a/taccsite_cms/settings_local.example.py b/taccsite_cms/settings_local.example.py index 016656def..22774e8fe 100644 --- a/taccsite_cms/settings_local.example.py +++ b/taccsite_cms/settings_local.example.py @@ -22,3 +22,7 @@ # To disable the Core-Portal integration PORTAL_IS_TACC_CORE_PORTAL = False PORTAL_HAS_LOGIN = False + +# To allow login in unique situations +# FAQ: If `BLOG_MULTISITE = True`, set `SESSION_COOKIE_SECURE=False` to be able to log in to CMS Admin at different domain (e.g. 0.0.0.0) +SESSION_COOKIE_SECURE = False