From 67f2b3d808fb7ba2179cfbfb4b3375a303094f91 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Jan 2021 13:13:19 -0800 Subject: [PATCH] Proper errorhandling for registration with invite --- bookwyrm/templates/invite.html | 9 ++++++++- bookwyrm/view_actions.py | 6 +++++- bookwyrm/views.py | 8 ++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bookwyrm/templates/invite.html b/bookwyrm/templates/invite.html index 42f564d6b..458ce3df7 100644 --- a/bookwyrm/templates/invite.html +++ b/bookwyrm/templates/invite.html @@ -3,7 +3,8 @@
-
diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index d27701b2c..16f537021 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -81,8 +81,12 @@ def register(request): if errors: data = { 'login_form': forms.LoginForm(), - 'register_form': form + 'register_form': form, + 'invite': invite, + 'valid': invite.valid() if invite else True, } + if invite: + return TemplateResponse(request, 'invite.html', data) return TemplateResponse(request, 'login.html', data) username = '%s@%s' % (localname, DOMAIN) diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 413039b4f..f1851da84 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -377,17 +377,13 @@ def invite_page(request, code): ''' endpoint for sending invites ''' if request.user.is_authenticated: return redirect('/') - try: - invite = models.SiteInvite.objects.get(code=code) - if not invite.valid(): - raise PermissionDenied - except models.SiteInvite.DoesNotExist: - raise PermissionDenied + invite = get_object_or_404(models.SiteInvite, code=code) data = { 'title': 'Join', 'register_form': forms.RegisterForm(), 'invite': invite, + 'valid': invite.valid() if invite else True, } return TemplateResponse(request, 'invite.html', data)