From c6797b450f9f6550f11decc12f9b36c8570cfaed Mon Sep 17 00:00:00 2001 From: Benjamin Ooghe-Tabanou Date: Wed, 24 Jul 2024 15:31:08 +0200 Subject: [PATCH] make SSL an env setting instead of profile_urls, built on top of scheme + host --- .env.example | 12 ++---------- annuaire/viewsets.py | 2 +- resin/settings.py | 8 ++++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index febd07e..088d459 100644 --- a/.env.example +++ b/.env.example @@ -3,18 +3,10 @@ RESIN_DEBUG=True # change that ! RESIN_SECRET=secret # change that ! RESIN_HOST=example.com # change that ! +RESIN_SSL=True # change that ! RESIN_DOCKER_CONTAINER=django # change that, maybe? RESIN_EMAIL_FROM=resin-noreply@example.com # change that ! -RESIN_EDIT_PROFILE_URL=http://example.com/edit-profile # change that ! -> URL to edit profile -# users will be redirected to http://example.com/edit-profile?uid=uid&token=token -# when they click on the link in the modification request email -# this page should contain the resin-formulaire component - -RESIN_PROFILE_URL=http://example.com/member # change that ! -> base URL for profiles -# users will be sent to http://example.com/member/[slug] -# when they click on the link in the registration confirmation email - ## Examples are default value if omitted ## # RESIN_EMAIL_HOST=localhost @@ -27,4 +19,4 @@ RESIN_PROFILE_URL=http://example.com/member # change that ! -> base URL for prof ## Settings specific to SSL/TLS on SMTP # RESIN_EMAIL_SSL_CERTFILE = "path/to/file" # needed in case of self-signed certificate -# RESIN_EMAIL_SSL_KEYFILE = "path/to/file" # needed in case of self-signed certificate \ No newline at end of file +# RESIN_EMAIL_SSL_KEYFILE = "path/to/file" # needed in case of self-signed certificate diff --git a/annuaire/viewsets.py b/annuaire/viewsets.py index dcb4239..bae29fc 100644 --- a/annuaire/viewsets.py +++ b/annuaire/viewsets.py @@ -72,7 +72,7 @@ def perform_create(self, serializer): ) ) admin_link = ( - "https://" + settings.RESIN_SCHEME + "://" + settings.RESIN_HOST + reverse("admin:annuaire_member_change", args=[serializer.instance.pk]) ) diff --git a/resin/settings.py b/resin/settings.py index 7ec43e7..ceac14d 100644 --- a/resin/settings.py +++ b/resin/settings.py @@ -28,6 +28,8 @@ RESIN_HOST = os.environ.get("RESIN_HOST", "localhost") +RESIN_SCHEME = "https" if os.environ.get("RESIN_SSL", "false").lower() in ["true", "yes", "y", "1"] else "http" + ALLOWED_HOSTS = [RESIN_HOST] RESIN_DOCKER_CONTAINER = os.environ.get("RESIN_DOCKER_CONTAINER") if RESIN_DOCKER_CONTAINER: @@ -122,10 +124,8 @@ *(["rest_framework.renderers.BrowsableAPIRenderer"] if DEBUG else []), ], } -EDIT_PROFILE_URL = os.environ.get( - "RESIN_EDIT_PROFILE_URL", "http://localhost:3000/s-inscrire" -) -PROFILE_URL = "https://" + RESIN_HOST + "/profile" +EDIT_PROFILE_URL = RESIN_SCHEME + "://" + RESIN_HOST + "/s-inscrire" +PROFILE_URL = RESIN_SCHEME + "://" + RESIN_HOST + "/profile" # Internationalization # https://docs.djangoproject.com/en/5.0/topics/i18n/