Allow running without CAS.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 7 Feb 2020 10:07:40 +0000 (11:07 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 7 Feb 2020 10:07:40 +0000 (11:07 +0100)
src/redakcja/settings/__init__.py
src/redakcja/urls.py

index db606b8..dd18ae6 100644 (file)
@@ -43,8 +43,14 @@ MIDDLEWARE = [
     'django.contrib.messages.middleware.MessageMiddleware',
 
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
 
     'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django_cas_ng.middleware.CASMiddleware',
+    ]
 
 
+if CAS_SERVER_URL:
+    MIDDLEWARE.append(
+        'django_cas_ng.middleware.CASMiddleware',
+    )
+
+MIDDLEWARE += [
     'django.contrib.admindocs.middleware.XViewMiddleware',
     'fnp_django_pagination.middleware.PaginationMiddleware',
     'maintenancemode.middleware.MaintenanceModeMiddleware',
     'django.contrib.admindocs.middleware.XViewMiddleware',
     'fnp_django_pagination.middleware.PaginationMiddleware',
     'maintenancemode.middleware.MaintenanceModeMiddleware',
@@ -55,10 +61,11 @@ if DEBUG:
         'debug_toolbar.middleware.DebugToolbarMiddleware',
     ] + MIDDLEWARE
 
         'debug_toolbar.middleware.DebugToolbarMiddleware',
     ] + MIDDLEWARE
 
-AUTHENTICATION_BACKENDS = (
-    'django.contrib.auth.backends.ModelBackend',
-    'django_cas_ng.backends.CASBackend',
-)
+if CAS_SERVER_URL:
+    AUTHENTICATION_BACKENDS = (
+        'django.contrib.auth.backends.ModelBackend',
+        'django_cas_ng.backends.CASBackend',
+    )
 
 ROOT_URLCONF = 'redakcja.urls'
 
 
 ROOT_URLCONF = 'redakcja.urls'
 
index 0e4dcea..9f5d6e0 100644 (file)
@@ -10,10 +10,8 @@ from django.views.generic import RedirectView
 import django_cas_ng.views
 
 
 import django_cas_ng.views
 
 
+
 urlpatterns = [
 urlpatterns = [
-    # Auth
-    url(r'^accounts/login/$', django_cas_ng.views.LoginView.as_view(), name='cas_ng_login'),
-    url(r'^accounts/logout/$', django_cas_ng.views.LogoutView.as_view(), name='logout'),
     #url(r'^admin/login/$', django_cas_ng.views.login, name='login'),
     #url(r'^admin/logout/$', django_cas_ng.views.logout, name='logout'),
 
     #url(r'^admin/login/$', django_cas_ng.views.login, name='login'),
     #url(r'^admin/logout/$', django_cas_ng.views.logout, name='logout'),
 
@@ -29,6 +27,20 @@ urlpatterns = [
     url(r'^cover/', include('cover.urls')),
 ]
 
     url(r'^cover/', include('cover.urls')),
 ]
 
+
+if settings.CAS_SERVER_URL:
+    urlpatterns += [
+        url(r'^accounts/login/$', django_cas_ng.views.LoginView.as_view(), name='cas_ng_login'),
+        url(r'^accounts/logout/$', django_cas_ng.views.LogoutView.as_view(), name='logout'),
+    ]
+else:
+    import django.contrib.auth.views
+    urlpatterns += [
+        url(r'^accounts/login/$', django.contrib.auth.views.LoginView.as_view(), name='cas_ng_login'),
+        url(r'^accounts/', include('django.contrib.auth.urls')),
+    ]
+
+
 if settings.DEBUG:
     urlpatterns += staticfiles_urlpatterns()
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 if settings.DEBUG:
     urlpatterns += staticfiles_urlpatterns()
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)