From be479fe4cb656740e48bb076dd45b584a82bab85 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Feb 2022 13:22:33 -0800 Subject: [PATCH] Adds warnings about misconfigurations --- bookwyrm/templates/setup/config.html | 30 +++++++++++++++++++++++++--- bookwyrm/views/setup.py | 7 ++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/setup/config.html b/bookwyrm/templates/setup/config.html index 44478b06..b14ad37d 100644 --- a/bookwyrm/templates/setup/config.html +++ b/bookwyrm/templates/setup/config.html @@ -23,6 +23,30 @@ {% endif %} + {% if warnings.invalid_domain %} +
+ + + {% blocktrans trimmed %} + Your domain appears to be misconfigured. + It should not include protocol or slashes. + {% endblocktrans %} + +
+ {% endif %} + + {% if warnings.protocol %} +
+ + + {% blocktrans trimmed %} + You are running BookWyrm in production mode without https. + USE_HTTPS should be enabled in production. + {% endblocktrans %} + +
+ {% endif %} +

{% trans "Settings" %}

@@ -82,14 +106,14 @@
- {% trans "Enable preview images" %} + {% trans "Enable preview images:" %}
{{ info.preview_images|yesno }}
- {% trans "Enable image thumbnails" %} + {% trans "Enable image thumbnails:" %}
{{ info.thumbnails|yesno }} @@ -104,7 +128,7 @@

{% trans "Does everything look right?" %}

{% blocktrans trimmed %} - This is your last change to set your domain and protocol. + This is your last chance to set your domain and protocol. {% endblocktrans %}

diff --git a/bookwyrm/views/setup.py b/bookwyrm/views/setup.py index 74505559..8fb968b4 100644 --- a/bookwyrm/views/setup.py +++ b/bookwyrm/views/setup.py @@ -1,4 +1,6 @@ """ Installation wizard 🧙 """ +import re + from django.contrib.auth import login from django.contrib.auth.models import Group from django.core.exceptions import PermissionDenied @@ -9,6 +11,7 @@ from django.views import View from bookwyrm import forms, models from bookwyrm import settings +from bookwyrm.utils import regex # pylint: disable= no-self-use @@ -25,8 +28,10 @@ class InstanceConfig(View): # check for possible problems with the instance configuration warnings = {} warnings["debug"] = settings.DEBUG - warnings["protocol_in_domain"] = settings.DOMAIN.startswith("http") + warnings["invalid_domain"] = not re.match(rf"^{regex.DOMAIN}$", settings.DOMAIN) + warnings["protocol"] = not settings.DEBUG and not settings.USE_HTTPS + # pylint: disable=line-too-long data = { "warnings": warnings, "info": {