Cleanup routing and remove middleware
This commit is contained in:
parent
4514d7e020
commit
de6088ca5f
7 changed files with 25 additions and 45 deletions
|
|
@ -1,27 +0,0 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.conf import settings
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class LoginRequiredMiddleware:
|
||||
"""
|
||||
If user is not accessing the site from an authorized IP, force
|
||||
authentification.
|
||||
"""
|
||||
def __init__(self, get_response):
|
||||
"""Init middleware"""
|
||||
self.get_response = get_response
|
||||
self.whitelist_re = re.compile("^/accounts/.*$")
|
||||
|
||||
def __call__(self, request):
|
||||
"""
|
||||
If user is not authenticated and external, redirect to login view
|
||||
before calling the view.
|
||||
"""
|
||||
if not request.user.is_authenticated:
|
||||
if not self.whitelist_re.match(request.path_info):
|
||||
return HttpResponseRedirect(settings.LOGIN_URL)
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
|
@ -77,7 +77,6 @@ MIDDLEWARE = [
|
|||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.contrib.sites.middleware.CurrentSiteMiddleware',
|
||||
'photo21.middleware.LoginRequiredMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'photo21.urls'
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
</li>
|
||||
{% if perms.photologue.add_gallery %}
|
||||
<li class="nav-item">
|
||||
{% url 'gallery-upload' as url %}
|
||||
{% url 'photologue:pl-gallery-upload' as url %}
|
||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}">{% trans 'Upload' %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,16 @@ from django.conf.urls.static import static
|
|||
|
||||
from .views import IndexView, MediaAccess
|
||||
|
||||
# photologue_custom overrides some photologue patterns
|
||||
urlpatterns = [
|
||||
path('', IndexView.as_view(), name='index'),
|
||||
path('photologue/', include('photologue_custom.urls')),
|
||||
path('photologue/', include('photologue.urls', namespace='photologue')),
|
||||
path('', include('photologue_custom.urls', namespace='photologue')),
|
||||
path('accounts/', include('allauth.urls')),
|
||||
path('i18n/', include('django.conf.urls.i18n')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
]
|
||||
|
||||
# In production media are served through NGINX with X-Accel-Redirect
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue