forked from mirrors/bookwyrm
Proper errorhandling for registration with invite
This commit is contained in:
parent
b046547a6e
commit
67f2b3d808
3 changed files with 15 additions and 8 deletions
|
@ -3,7 +3,8 @@
|
|||
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="block login">
|
||||
<div class="block">
|
||||
{% if valid %}
|
||||
<h1 class="title">Create an Account</h1>
|
||||
<div>
|
||||
<form name="register" method="post" action="/user-register">
|
||||
|
@ -11,6 +12,12 @@
|
|||
{% include 'snippets/register_form.html' %}
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="content">
|
||||
<h1 class="title">Permission Denied</h1>
|
||||
<p>Sorry! This invite code is no longer valid.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue