Skip to content

Commit

Permalink
fix login paths for admin, redirect /admin to admin subdomain
Browse files Browse the repository at this point in the history
  • Loading branch information
ludvigalden committed Jan 25, 2024
1 parent 2a6cbbf commit 2c3e571
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/admin/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from __future__ import absolute_import, unicode_literals

from django.conf.urls import include, url

from wagtail.core import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from django.urls import path, include
from moore.urls import urlpatterns as base_urlpatterns

# Use the same `urlpatterns` as other domains as the base
urlpatterns = base_urlpatterns.copy()

urlpatterns = [
path(r'', include(wagtailadmin_urls)),
]
# Append `wagtailadmin_urls` before `wagtail_urls`
for index, pattern in enumerate(urlpatterns):
if hasattr(pattern, 'url_patterns'):
if wagtail_urls.urlpatterns == pattern.url_patterns:
# Insert the new_pattern before the wagtail include
urlpatterns.insert(index, url(r'', include(wagtailadmin_urls)))
break
11 changes: 11 additions & 0 deletions src/admin/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.conf import settings
from django_hosts.resolvers import reverse_host
from django.http import HttpResponseRedirect


def redirect_admin(request, path):
protocol = 'https' if request.is_secure() else 'http'
host = reverse_host(host='admin')
if getattr(settings, 'HOST_PORT', None):
host = f"{host}:{settings.HOST_PORT}"
return HttpResponseRedirect(f'{protocol}://{host}/{path}')
2 changes: 2 additions & 0 deletions src/moore/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
BASE_URL = 'http://localhost:8000'

ALLOWED_HOSTS = ['admin.localhost', 'localhost']
PARENT_HOST = 'localhost'
HOST_PORT = '8000'
# Email
# https://docs.djangoproject.com/en/1.10/ref/settings/#email-backend

Expand Down
1 change: 1 addition & 0 deletions src/moore/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
BASE_URL = 'https://utn.se'

ALLOWED_HOSTS = ['.utn.se', '.utnarm.se']
PARENT_HOST = 'utn.se'

# Email settings
DEFAULT_FROM_EMAIL = '[email protected]'
Expand Down
9 changes: 5 additions & 4 deletions src/moore/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

from django.conf import settings
from django.conf.urls import include, url
from django.urls import path
from django.urls import path, re_path

from search import views as search_views
from wagtail.admin import urls as wagtailadmin_urls
# from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

from .api import api_router

from members.views import member_check_api
from admin.views import redirect_admin

urlpatterns = [

# Needs to be imported before wagtail urls
url(r'^api/', api_router.urls),

Expand All @@ -23,7 +23,8 @@
url(r'', include('events.urls')),
path('member_check_api/', member_check_api, name='member_check_api'),

url(r'^admin/', include(wagtailadmin_urls)),
re_path(r'^admin/(?P<path>.*)$', redirect_admin),

url(r'^documents/', include(wagtaildocs_urls)),

url(r'^search/$', search_views.search, name='search'),
Expand Down

0 comments on commit 2c3e571

Please sign in to comment.