From d15396eb26c1352bc713bc603ad1057b24be6eee Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 20 Mar 2021 19:14:41 -0700 Subject: [PATCH] Request invite flow --- bookwyrm/forms.py | 8 +++++++ .../templates/discover/landing_layout.html | 24 +++++++++++++++++++ bookwyrm/templates/settings/site.html | 4 ++++ bookwyrm/urls.py | 3 +++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/helpers.py | 19 ++++++++++++++- bookwyrm/views/invite.py | 20 ++++++++++++++++ bookwyrm/views/landing.py | 17 +++---------- 8 files changed, 81 insertions(+), 16 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 0a69dbe0..d330211c 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -3,6 +3,7 @@ import datetime from collections import defaultdict from django import forms +from django.core.exceptions import ValidationError from django.forms import ModelForm, PasswordInput, widgets from django.forms.widgets import Textarea from django.utils import timezone @@ -203,6 +204,13 @@ class ExpiryWidget(widgets.Select): class InviteRequestForm(CustomForm): + def clean(self): + """ make sure the email isn't in use by a registered user """ + cleaned_data = super().clean() + email = cleaned_data.get("email") + if email and models.User.objects.filter(email=email).exists(): + self.add_error("email", _("A user with this email already exists.")) + class Meta: model = models.InviteRequest fields = ["email"] diff --git a/bookwyrm/templates/discover/landing_layout.html b/bookwyrm/templates/discover/landing_layout.html index 5cfa1fd3..8e507531 100644 --- a/bookwyrm/templates/discover/landing_layout.html +++ b/bookwyrm/templates/discover/landing_layout.html @@ -45,9 +45,33 @@
{% include 'snippets/register_form.html' %}
+ {% else %} +

{% trans "This instance is closed" %}

{{ site.registration_closed_text | safe}}

+ + {% if site.allow_invite_requests %} + {% if request_received %} +

+ {% trans "Thank you! Your request has been received." %} +

+ {% else %} +

{% trans "Request an Invitation" %}

+
+ {% csrf_token %} +
+ + + {% for error in request_form.email.errors %} +

{{ error | escape }}

+ {% endfor %} +
+ +
+ {% endif %} + {% endif %} + {% endif %} {% else %} diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 27be0c9b..28009e1a 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -79,6 +79,10 @@