diff --git a/tfjm/settings.py b/tfjm/settings.py index e0c28da..1b02629 100644 --- a/tfjm/settings.py +++ b/tfjm/settings.py @@ -98,19 +98,6 @@ FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' WSGI_APPLICATION = 'tfjm.wsgi.application' -# Database -# https://docs.djangoproject.com/en/3.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - - # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators @@ -185,3 +172,8 @@ MEDIA_ROOT = os.path.join(BASE_DIR, "media") CRISPY_TEMPLATE_PACK = 'bootstrap4' DJANGO_TABLES2_TEMPLATE = 'django_tables2/bootstrap4.html' + +if os.getenv("TFJM_STAGE", "dev") == "prod": + from .settings_prod import * +else: + from .settings_dev import * diff --git a/tfjm/settings_dev.py b/tfjm/settings_dev.py new file mode 100644 index 0000000..3648467 --- /dev/null +++ b/tfjm/settings_dev.py @@ -0,0 +1,15 @@ +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +import os + +from tfjm.settings import BASE_DIR + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/tfjm/settings_prod.py b/tfjm/settings_prod.py new file mode 100644 index 0000000..a9dd4d2 --- /dev/null +++ b/tfjm/settings_prod.py @@ -0,0 +1,39 @@ +import os + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.environ.get('DJANGO_DB_NAME', 'tfjm'), + 'USER': os.environ.get('DJANGO_DB_USER', 'tfjm'), + 'PASSWORD': os.environ.get('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS'), + 'HOST': os.environ.get('DJANGO_DB_HOST', 'localhost'), + 'PORT': os.environ.get('DJANGO_DB_PORT', ''), # Use default port + } +} + +# Break it, fix it! +DEBUG = False + +# Mandatory ! +ALLOWED_HOSTS = ['inscription.tfjm.org'] + +SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS') + +# Emails +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_USE_SSL = True +EMAIL_HOST = os.getenv("EMAIL_HOST") +EMAIL_PORT = os.getenv("EMAIL_PORT") +EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER") +EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") + +SERVER_EMAIL = 'contact@tfjm.org' + +# Security settings +SECURE_CONTENT_TYPE_NOSNIFF = False +SECURE_BROWSER_XSS_FILTER = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +CSRF_COOKIE_HTTPONLY = False +X_FRAME_OPTIONS = 'DENY' +SESSION_COOKIE_AGE = 60 * 60 * 3