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 @@