From 73b8fc96d4602dff5ca521ad3c1655ddc6aa660b Mon Sep 17 00:00:00 2001 From: "R. Miles McCain" Date: Tue, 14 Apr 2020 15:18:45 -0400 Subject: [PATCH] Prepare for public deployment --- Pipfile | 1 + Pipfile.lock | 21 ++++++++++++++- kubernetes/secrets_template.yml | 1 + shynet/dashboard/apps.py | 8 +++++- shynet/dashboard/templates/account/login.html | 3 +++ shynet/shynet/settings.py | 27 ++++++++++++++----- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Pipfile b/Pipfile index bc36461..72284b4 100644 --- a/Pipfile +++ b/Pipfile @@ -19,6 +19,7 @@ user-agents = "*" emoji-country-flag = "*" rules = "*" gunicorn = "*" +psycopg2 = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index d87fd30..a695d4c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "c1d7cd1455c79f65e139ba93673e58446c8094311b329be28d44d23fd5510462" + "sha256": "11fb482879db5415b0e23111fa01c485ef40663567bb5837fe02d9c2dbf0e337" }, "pipfile-spec": 6, "requires": { @@ -147,6 +147,25 @@ ], "version": "==3.1.0" }, + "psycopg2": { + "hashes": [ + "sha256:132efc7ee46a763e68a815f4d26223d9c679953cd190f1f218187cb60decf535", + "sha256:2327bf42c1744a434ed8ed0bbaa9168cac7ee5a22a9001f6fc85c33b8a4a14b7", + "sha256:27c633f2d5db0fc27b51f1b08f410715b59fa3802987aec91aeb8f562724e95c", + "sha256:2c0afb40cfb4d53487ee2ebe128649028c9a78d2476d14a67781e45dc287f080", + "sha256:2df2bf1b87305bd95eb3ac666ee1f00a9c83d10927b8144e8e39644218f4cf81", + "sha256:440a3ea2c955e89321a138eb7582aa1d22fe286c7d65e26a2c5411af0a88ae72", + "sha256:6a471d4d2a6f14c97a882e8d3124869bc623f3df6177eefe02994ea41fd45b52", + "sha256:6b306dae53ec7f4f67a10942cf8ac85de930ea90e9903e2df4001f69b7833f7e", + "sha256:a0984ff49e176062fcdc8a5a2a670c9bb1704a2f69548bce8f8a7bad41c661bf", + "sha256:ac5b23d0199c012ad91ed1bbb971b7666da651c6371529b1be8cbe2a7bf3c3a9", + "sha256:acf56d564e443e3dea152efe972b1434058244298a94348fc518d6dd6a9fb0bb", + "sha256:d3b29d717d39d3580efd760a9a46a7418408acebbb784717c90d708c9ed5f055", + "sha256:f7d46240f7a1ae1dd95aab38bd74f7428d46531f69219954266d669da60c0818" + ], + "index": "pypi", + "version": "==2.8.5" + }, "python3-openid": { "hashes": [ "sha256:0086da6b6ef3161cfe50fb1ee5cceaf2cda1700019fda03c2c5c440ca6abe4fa", diff --git a/kubernetes/secrets_template.yml b/kubernetes/secrets_template.yml index 452bc0c..058a6f4 100644 --- a/kubernetes/secrets_template.yml +++ b/kubernetes/secrets_template.yml @@ -8,6 +8,7 @@ stringData: DEBUG: "False" ALLOWED_HOSTS: "*" # For better security, set this to your deployment's domain. Comma separated. DJANGO_SECRET_KEY: "" + SIGNUPS_ENABLED: "False" # Redis configuration (if you use the default Kubernetes config, this will work) REDIS_CACHE_LOCATION: "redis://redis.default.svc.cluster.local/0" diff --git a/shynet/dashboard/apps.py b/shynet/dashboard/apps.py index 50878e7..f470ac5 100644 --- a/shynet/dashboard/apps.py +++ b/shynet/dashboard/apps.py @@ -1,5 +1,11 @@ from django.apps import AppConfig - +from django.conf import settings class DashboardConfig(AppConfig): name = 'dashboard' + + def ready(self): + if not settings.ACCOUNT_SIGNUPS_ENABLED: + # Normally you'd do this in settings.py, but this must be done _after_ apps are enabled + from allauth.account.adapter import DefaultAccountAdapter + DefaultAccountAdapter.is_open_for_signup = lambda k, v: False diff --git a/shynet/dashboard/templates/account/login.html b/shynet/dashboard/templates/account/login.html index cd0a04e..efe3288 100644 --- a/shynet/dashboard/templates/account/login.html +++ b/shynet/dashboard/templates/account/login.html @@ -8,6 +8,9 @@ {% block card %}
+ {% csrf_token %} {{ form|a17t }} {% if redirect_field_value %} diff --git a/shynet/shynet/settings.py b/shynet/shynet/settings.py index 79a385e..c274ab4 100644 --- a/shynet/shynet/settings.py +++ b/shynet/shynet/settings.py @@ -45,7 +45,7 @@ INSTALLED_APPS = [ "rules.apps.AutodiscoverRulesConfig", "a17t", "core", - "dashboard", + "dashboard.apps.DashboardConfig", "analytics", "allauth", "allauth.account", @@ -87,12 +87,24 @@ WSGI_APPLICATION = "shynet.wsgi.application" # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), +if os.getenv("SQLITE", "False") == "True": + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + } + } +else: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql_psycopg2", + "NAME": os.environ.get("DB_NAME"), + "USER": os.environ.get("DB_USER"), + "PASSWORD": os.environ.get("DB_PASSWORD"), + "HOST": os.environ.get("DB_HOST"), + "PORT": os.environ.get("DB_PORT"), + } } -} # Password validation @@ -147,8 +159,9 @@ ACCOUNT_USERNAME_REQUIRED = False ACCOUNT_EMAIL_VERIFICATION = "mandatory" ACCOUNT_EMAIL_SUBJECT_PREFIX = "" ACCOUNT_USER_DISPLAY = lambda k: k.email +ACCOUNT_SIGNUPS_ENABLED = os.getenv("SIGNUPS_ENABLED", "False") == True -LOGIN_REDIRECT_URL = "/dash" +LOGIN_REDIRECT_URL = "/" SITE_ID = 1