diff --git a/bocal/__init__.py b/app/__init__.py similarity index 100% rename from bocal/__init__.py rename to app/__init__.py diff --git a/app/settings_base.py b/app/settings_base.py new file mode 100644 index 0000000..0c5f35a --- /dev/null +++ b/app/settings_base.py @@ -0,0 +1,103 @@ +""" +Django settings for bocal project. + +Generated by 'django-admin startproject' using Django 1.11.5. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# Public dir: a good base path for MEDIA_ROOT and STATIC_ROOT +PUBLIC_DIR = os.path.join(BASE_DIR, "public") + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "solo", + "markdownx", + "django_cas_ng", + "mainsite", + "api", + "bocal_auth", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_cas_ng.middleware.CASMiddleware", +] + +ROOT_URLCONF = "bocal.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + "mainsite.context_processors.sidebar_years", + ], + }, + }, +] + +WSGI_APPLICATION = "bocal.wsgi.application" + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + +AUTHENTICATION_BACKENDS = [ + "django.contrib.auth.backends.ModelBackend", + "bocal_auth.cas_backend.BOcalCASBackend", +] + +CAS_ADMIN_PREFIX = "/yaes5eiS" # we don't want CAS to take over /admin auth + +LOGIN_URL = "/accounts/login" +LOGIN_REDIRECT_URL = "/" + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = "/static/" +MEDIA_URL = "/media/" diff --git a/bocal/settings_dev.py b/app/settings_dev.py similarity index 53% rename from bocal/settings_dev.py rename to app/settings_dev.py index 0045043..b4027e2 100644 --- a/bocal/settings_dev.py +++ b/app/settings_dev.py @@ -1,10 +1,11 @@ import os + from .settings_base import * # SECURITY WARNING: keep the secret key used in production secret! # For production, generate a fresh one, eg. with # pwgen -sy 60 1 -SECRET_KEY = 'k340m-_mw#i#up8ajv9$$=$tgpji3f3j!jafj2+ken*@wo9u0%' +SECRET_KEY = "k340m-_mw#i#up8ajv9$$=$tgpji3f3j!jafj2+ken*@wo9u0%" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -14,16 +15,16 @@ ALLOWED_HOSTS = [] # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ -LANGUAGE_CODE = 'fr-fr' -TIME_ZONE = 'Europe/Paris' +LANGUAGE_CODE = "fr-fr" +TIME_ZONE = "Europe/Paris" USE_I18N = True USE_L10N = True @@ -31,18 +32,18 @@ USE_TZ = True # Paths -STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') -MEDIA_ROOT = os.path.join(PUBLIC_DIR, 'media') +STATIC_ROOT = os.path.join(PUBLIC_DIR, "static") +MEDIA_ROOT = os.path.join(PUBLIC_DIR, "media") # Cas -CAS_SERVER_URL = 'https://cas.eleves.ens.fr/' -CAS_VERIFY_URL = 'https://cas.eleves.ens.fr/' -CAS_VERSION = 'CAS_2_SAML_1_0' +CAS_SERVER_URL = "https://cas.eleves.ens.fr/" +CAS_VERIFY_URL = "https://cas.eleves.ens.fr/" +CAS_VERSION = "CAS_2_SAML_1_0" CAS_IGNORE_REFERER = True -CAS_FORCE_CHANGE_USERNAME_CASE = 'lower' -CAS_REDIRECT_URL = '/' +CAS_FORCE_CHANGE_USERNAME_CASE = "lower" +CAS_REDIRECT_URL = "/" CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" CAS_LOGOUT_COMPLETELY = False # Auth -RHOSTS_PATH = 'rhosts_dev' +RHOSTS_PATH = "rhosts_dev" diff --git a/app/settings_prod.py b/app/settings_prod.py new file mode 100644 index 0000000..e84ea85 --- /dev/null +++ b/app/settings_prod.py @@ -0,0 +1,60 @@ +import os + +from .settings_base import * + +# SECURITY WARNING: keep the secret key used in production secret! +# For production, generate a fresh one, eg. with +# pwgen -sy 60 1 +SECRET_KEY = "CHANGEMEQUICKLY" # FIXME + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = [ + "localhost", +] # FIXME: add your domain name(s) here. + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases +DATABASES = { + "default": { # FIXME add real settings + "ENGINE": "django.db.backends.postgresql", + "NAME": "", # DB name + "USER": "", # DB user + "PASSWORD": "", # user's password + "HOST": "localhost", # DB host -- change if DB is not local + "PORT": "5432", # DB port -- 5432 is the default port for postgres + }, + # Alternatively, use sqlite3 (if you don't really have a choice…) + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + # } +} + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ +LANGUAGE_CODE = "fr-fr" +TIME_ZONE = "Europe/Paris" + +USE_I18N = True +USE_L10N = True +USE_TZ = True + +# Paths + +STATIC_ROOT = os.path.join(PUBLIC_DIR, "static") +MEDIA_ROOT = os.path.join(PUBLIC_DIR, "media") + +# Cas +CAS_SERVER_URL = "https://example.com/" # FIXME +CAS_VERIFY_URL = "https://example.com/" # FIXME +CAS_VERSION = "CAS_2_SAML_1_0" # FIXME +CAS_IGNORE_REFERER = True +CAS_FORCE_CHANGE_USERNAME_CASE = "lower" +CAS_REDIRECT_URL = "/" +CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" # FIXME +CAS_LOGOUT_COMPLETELY = False + +# Auth +RHOSTS_PATH = "" # FIXME (path to BOcal's .rhosts) diff --git a/bocal/urls.py b/app/urls.py similarity index 96% rename from bocal/urls.py rename to app/urls.py index 9b18c9d..6545f36 100644 --- a/bocal/urls.py +++ b/app/urls.py @@ -1,16 +1,14 @@ -from django.urls import path, include +import django.contrib.auth.views as dj_auth_views +import django_cas_ng.views +import markdownx.urls from django.contrib import admin from django.contrib.auth.decorators import login_required -import django.contrib.auth.views as dj_auth_views +from django.urls import include, path -import mainsite.urls -import bocal_auth.views as auth_views -from bocal_auth.rhosts import forceReevalRhosts -import markdownx.urls import api.urls - -import django_cas_ng.views - +import bocal_auth.views as auth_views +import mainsite.urls +from bocal_auth.rhosts import forceReevalRhosts # Force the user to login through the custom login page admin.site.login = login_required(forceReevalRhosts(admin.site.login)) diff --git a/bocal/wsgi.py b/app/wsgi.py similarity index 100% rename from bocal/wsgi.py rename to app/wsgi.py diff --git a/bocal/.gitignore b/bocal/.gitignore deleted file mode 100644 index fce19e4..0000000 --- a/bocal/.gitignore +++ /dev/null @@ -1 +0,0 @@ -settings.py diff --git a/bocal/settings_base.py b/bocal/settings_base.py deleted file mode 100644 index 2c2858e..0000000 --- a/bocal/settings_base.py +++ /dev/null @@ -1,103 +0,0 @@ -""" -Django settings for bocal project. - -Generated by 'django-admin startproject' using Django 1.11.5. - -For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# Public dir: a good base path for MEDIA_ROOT and STATIC_ROOT -PUBLIC_DIR = os.path.join(BASE_DIR, 'public') - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'solo', - 'markdownx', - 'django_cas_ng', - 'mainsite', - 'api', - 'bocal_auth', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django_cas_ng.middleware.CASMiddleware', -] - -ROOT_URLCONF = 'bocal.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - 'mainsite.context_processors.sidebar_years', - ], - }, - }, -] - -WSGI_APPLICATION = 'bocal.wsgi.application' - - -# Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - -AUTHENTICATION_BACKENDS = [ - 'django.contrib.auth.backends.ModelBackend', - 'bocal_auth.cas_backend.BOcalCASBackend', -] - -CAS_ADMIN_PREFIX = '/yaes5eiS' # we don't want CAS to take over /admin auth - -LOGIN_URL = '/accounts/login' -LOGIN_REDIRECT_URL = '/' - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ - -STATIC_URL = '/static/' -MEDIA_URL = '/media/' diff --git a/bocal/settings_prod.py b/bocal/settings_prod.py deleted file mode 100644 index 2aad1d8..0000000 --- a/bocal/settings_prod.py +++ /dev/null @@ -1,59 +0,0 @@ -import os -from .settings_base import * - -# SECURITY WARNING: keep the secret key used in production secret! -# For production, generate a fresh one, eg. with -# pwgen -sy 60 1 -SECRET_KEY = 'CHANGEMEQUICKLY' # FIXME - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False - -ALLOWED_HOSTS = ['localhost', - ] # FIXME: add your domain name(s) here. - -# Database -# https://docs.djangoproject.com/en/1.11/ref/settings/#databases -DATABASES = { - 'default': { # FIXME add real settings - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': '', # DB name - 'USER': '', # DB user - 'PASSWORD': '', # user's password - 'HOST': 'localhost', # DB host -- change if DB is not local - 'PORT': '5432', # DB port -- 5432 is the default port for postgres - }, - - # Alternatively, use sqlite3 (if you don't really have a choice…) - # 'default': { - # 'ENGINE': 'django.db.backends.sqlite3', - # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - # } -} - -# Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ -LANGUAGE_CODE = 'fr-fr' -TIME_ZONE = 'Europe/Paris' - -USE_I18N = True -USE_L10N = True -USE_TZ = True - -# Paths - -STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') -MEDIA_ROOT = os.path.join(PUBLIC_DIR, 'media') - -# Cas -CAS_SERVER_URL = 'https://example.com/' # FIXME -CAS_VERIFY_URL = 'https://example.com/' # FIXME -CAS_VERSION = 'CAS_2_SAML_1_0' # FIXME -CAS_IGNORE_REFERER = True -CAS_FORCE_CHANGE_USERNAME_CASE = 'lower' -CAS_REDIRECT_URL = '/' -CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" # FIXME -CAS_LOGOUT_COMPLETELY = False - -# Auth -RHOSTS_PATH = '' # FIXME (path to BOcal's .rhosts)