diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 564ea91b2..b96e152f0 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -54,6 +54,15 @@ class RegisterForm(CustomForm): help_texts = {f: None for f in fields} widgets = {"password": PasswordInput()} + def clean(self): + """Check if the username is taken""" + cleaned_data = super().clean() + localname = cleaned_data.get("localname").strip() + if models.User.objects.filter(localname=localname).first(): + self.add_error( + "localname", _("User with this username already exists") + ) + class RatingForm(CustomForm): class Meta: diff --git a/bookwyrm/templates/setup/admin.html b/bookwyrm/templates/setup/admin.html index 8bba55a8d..ecc84c7e5 100644 --- a/bookwyrm/templates/setup/admin.html +++ b/bookwyrm/templates/setup/admin.html @@ -13,7 +13,7 @@