From 96ccb563c5f860e67abae92cb372ac45e9a7415d Mon Sep 17 00:00:00 2001
From: Zdenek Kubala <zdenek.kubala@pirati.cz>
Date: Wed, 8 Sep 2021 07:19:11 +0000
Subject: [PATCH] set production env vars

---
 django_apps/settings.py        | 24 ++++++++++++++++++++----
 django_apps/urls.py            |  1 +
 sifrovacka/templates/base.html |  8 ++++----
 sifrovacka/urls.py             |  2 ++
 4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/django_apps/settings.py b/django_apps/settings.py
index 012e16b..471fd25 100644
--- a/django_apps/settings.py
+++ b/django_apps/settings.py
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
 """
 
 from pathlib import Path
+from os import getenv
 
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = Path(__file__).resolve().parent.parent
@@ -20,11 +21,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent
 # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'django-insecure-kog+-x*xtt5e7shmxa-ddldzdtz@u#*tj^s9jzm#%&ghy*a8x%'
+SECRET_KEY = getenv('SECRET_KEY')
 
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = False
-#DEBUG = True
+#DEBUG = False
+
+DJANGO_ENV = getenv('DJANGO_ENV', 'production').lower()
+if DJANGO_ENV == 'local':
+    DEBUG = True
+elif DJANGO_ENV == 'production':
+    DEBUG = False
+
 
 ALLOWED_HOSTS = ['*']
 
@@ -86,6 +93,9 @@ DATABASES = {
     }
 }
 
+if DJANGO_ENV == 'production':
+    DATABASES = {"default": env.db("DATABASE_URL")}
+
 
 # Password validation
 # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
@@ -136,7 +146,6 @@ LOGIN_REDIRECT_URL = 'home'
 LOGOUT_REDIRECT_URL = 'index'
 
 # Custom settings STATIC
-STATIC_URL = "/static/"
 STATIC_ROOT = BASE_DIR / 'static'
 #STATICFILES_DIRS = BASE_DIR / 'static'
 
@@ -172,3 +181,10 @@ TINYMCE_DEFAULT_CONFIG = {
     'statusbar': True,
 }
 
+# Custom settings Registration
+ACCOUNT_ACTIVATION_DAYS = 7
+EMAIL_HOST = 'mail2.playzone.cz'
+EMAIL_PORT = 587
+EMAIL_USE_TLS = True
+EMAIL_HOST_USER = getenv('SMTP_USER')
+EMAIL_HOST_PASSWORD = getenv('SMTP_PASSWORD')
diff --git a/django_apps/urls.py b/django_apps/urls.py
index e70575b..056b747 100644
--- a/django_apps/urls.py
+++ b/django_apps/urls.py
@@ -27,3 +27,4 @@ urlpatterns = [
 if settings.DEBUG:
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
     urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+
diff --git a/sifrovacka/templates/base.html b/sifrovacka/templates/base.html
index 079c67e..bbcf883 100644
--- a/sifrovacka/templates/base.html
+++ b/sifrovacka/templates/base.html
@@ -41,11 +41,11 @@
     outline: none;
     font-size: 15px;
   }
-  
+
   .active, .collapsible:hover {
     background-color: #555;
   }
-  
+
   .content {
     padding: 0 18px;
     overflow: hidden;
@@ -53,7 +53,7 @@
     max-height: 0;
     transition: max-height 0.2s ease-out;
   }
-  </style>  
+  </style>
 
   {% if settings.SIFROVACKA_ENV == "prod" and settings.ONBOARDING_MATOMO_ID %}
     {% include "shared/matomo_snippet.html" with matomo_id=settings.ONBOARDING_MATOMO_ID %}
@@ -72,7 +72,7 @@
     <div>
       <div class="container container--wide navbar__content navbar__content--initialized">
         <div class="navbar__brand my-4 flex items-center lg:pr-8 lg:my-0">
-          <a href="/"><img src="https://styleguide.pir-test.eu/2.3.x/images/logo-round-white.svg" class="w-8"></a>
+          <img src="https://styleguide.pir-test.eu/2.3.x/images/logo-round-white.svg" class="w-8">
           <span class="pl-4 font-bold text-xl lg:border-r lg:border-grey-300 lg:pr-8">
            <a href={% url "index"%}>Šifrovačka</a>
             {% if settings.SIFROVACKA_ENV == "dev" %}<sup class="text-cyan-100">(DEV)</sup>{% endif %}
diff --git a/sifrovacka/urls.py b/sifrovacka/urls.py
index 1183f08..88089ca 100644
--- a/sifrovacka/urls.py
+++ b/sifrovacka/urls.py
@@ -6,6 +6,8 @@ from . import views
 
 urlpatterns = [
     # accounts uls
+#   two step auth not working yet
+#    path('accounts/', include('django_registration.backends.activation.urls')),
     path('accounts/', include('django_registration.backends.one_step.urls')),
     path('accounts/', include('django.contrib.auth.urls')),
     # the 'name' value as called by the {% url %} template tag
-- 
GitLab