Disallow registration in install mode and adds redirects

This commit is contained in:
Mouse Reeve 2022-02-17 10:52:12 -08:00
parent 8e3c39d319
commit b4e0749f73
4 changed files with 19 additions and 4 deletions

View file

@ -59,7 +59,7 @@ urlpatterns = [
name="stream-updates", name="stream-updates",
), ),
# instance setup # instance setup
re_path(r"^setup/?$", views.CreateAdmin.as_view(), name="setup-admin"), re_path(r"^setup/?$", views.CreateAdmin.as_view(), name="setup"),
# authentication # authentication
re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^login/?$", views.Login.as_view(), name="login"),
re_path(r"^login/(?P<confirmed>confirmed)/?$", views.Login.as_view(), name="login"), re_path(r"^login/(?P<confirmed>confirmed)/?$", views.Login.as_view(), name="login"),

View file

@ -1,8 +1,9 @@
""" non-interactive pages """ """ non-interactive pages """
from django.shortcuts import redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.views import View from django.views import View
from bookwyrm import forms from bookwyrm import forms, models
from bookwyrm.views.feed import Feed from bookwyrm.views.feed import Feed
@ -15,6 +16,11 @@ class Home(View):
if request.user.is_authenticated: if request.user.is_authenticated:
feed_view = Feed.as_view() feed_view = Feed.as_view()
return feed_view(request, "home") return feed_view(request, "home")
site = models.SiteSettings.objects.get()
if site.install_mode:
return redirect("setup")
landing_view = Landing.as_view() landing_view = Landing.as_view()
return landing_view(request) return landing_view(request)

View file

@ -25,6 +25,10 @@ class Register(View):
def post(self, request): def post(self, request):
"""join the server""" """join the server"""
settings = models.SiteSettings.get() settings = models.SiteSettings.get()
# no registration allowed when the site is being installed
if settings.install_mode:
raise PermissionDenied()
if not settings.allow_registration: if not settings.allow_registration:
invite_code = request.POST.get("invite_code") invite_code = request.POST.get("invite_code")

View file

@ -1,9 +1,9 @@
""" Installation wizard 🧙 """ """ Installation wizard 🧙 """
from django.core.exceptions import PermissionDenied
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from bookwyrm import emailing, forms, models from bookwyrm import forms, models
# pylint: disable= no-self-use # pylint: disable= no-self-use
@ -12,6 +12,11 @@ class CreateAdmin(View):
def get(self, request): def get(self, request):
"""Create admin user""" """Create admin user"""
# only allow this view when an instance is being installed
site = models.SiteSettings.objects.get()
if not site.install_mode:
raise PermissionDenied()
data = { data = {
"register_form": forms.RegisterForm() "register_form": forms.RegisterForm()
} }