diff --git a/.env.example b/.env.example index 7769a67b..31e46447 100644 --- a/.env.example +++ b/.env.example @@ -41,7 +41,7 @@ REDIS_BROKER_PASSWORD=redispassword123 # Monitoring for celery FLOWER_PORT=8888 -FLOWER_USER=mouse +FLOWER_USER=admin FLOWER_PASSWORD=changeme # Email config diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 564ea91b..cb9a1e97 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -54,6 +54,13 @@ 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/management/commands/admin_code.py b/bookwyrm/management/commands/admin_code.py new file mode 100644 index 00000000..ee69b78c --- /dev/null +++ b/bookwyrm/management/commands/admin_code.py @@ -0,0 +1,23 @@ +""" Get your admin code to allow install """ +from django.core.management.base import BaseCommand + +from bookwyrm import models + + +def get_admin_code(): + """get that code""" + return models.SiteSettings.objects.get().admin_code + + +class Command(BaseCommand): + """command-line options""" + + help = "Gets admin code for configuring BookWyrm" + + # pylint: disable=unused-argument + def handle(self, *args, **options): + """execute init""" + self.stdout.write("*******************************************") + self.stdout.write("Use this code to create your admin account:") + self.stdout.write(get_admin_code()) + self.stdout.write("*******************************************") diff --git a/bookwyrm/management/commands/generate_preview_images.py b/bookwyrm/management/commands/generate_preview_images.py index df218623..0454e5e5 100644 --- a/bookwyrm/management/commands/generate_preview_images.py +++ b/bookwyrm/management/commands/generate_preview_images.py @@ -10,7 +10,9 @@ class Command(BaseCommand): help = "Generate preview images" + # pylint: disable=no-self-use def add_arguments(self, parser): + """options for how the command is run""" parser.add_argument( "--all", "-a", @@ -38,6 +40,7 @@ class Command(BaseCommand): preview_images.generate_site_preview_image_task.delay() self.stdout.write(" OK 🖼") + # pylint: disable=consider-using-f-string if options["all"]: # Users users = models.User.objects.filter( diff --git a/bookwyrm/management/commands/initdb.py b/bookwyrm/management/commands/initdb.py index 09d86462..4e23a530 100644 --- a/bookwyrm/management/commands/initdb.py +++ b/bookwyrm/management/commands/initdb.py @@ -120,6 +120,7 @@ def init_settings(): models.SiteSettings.objects.create( support_link="https://www.patreon.com/bookwyrm", support_title="Patreon", + install_mode=True, ) diff --git a/bookwyrm/migrations/0136_auto_20220217_1708.py b/bookwyrm/migrations/0136_auto_20220217_1708.py new file mode 100644 index 00000000..916fb124 --- /dev/null +++ b/bookwyrm/migrations/0136_auto_20220217_1708.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.12 on 2022-02-17 17:08 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0135_auto_20220217_1624"), + ] + + operations = [ + migrations.AddField( + model_name="sitesettings", + name="admin_code", + field=models.CharField(default=uuid.uuid4, max_length=50), + ), + migrations.AddField( + model_name="sitesettings", + name="install_mode", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/migrations/0137_alter_sitesettings_allow_registration.py b/bookwyrm/migrations/0137_alter_sitesettings_allow_registration.py new file mode 100644 index 00000000..ba5000ac --- /dev/null +++ b/bookwyrm/migrations/0137_alter_sitesettings_allow_registration.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-02-17 19:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0136_auto_20220217_1708"), + ] + + operations = [ + migrations.AlterField( + model_name="sitesettings", + name="allow_registration", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index b2119e23..a40d295b 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -1,6 +1,7 @@ """ the particulars for this instance of BookWyrm """ import datetime from urllib.parse import urljoin +import uuid from django.db import models, IntegrityError from django.dispatch import receiver @@ -24,6 +25,10 @@ class SiteSettings(models.Model): instance_description = models.TextField(default="This instance has no description.") instance_short_description = models.CharField(max_length=255, blank=True, null=True) + # admin setup options + install_mode = models.BooleanField(default=False) + admin_code = models.CharField(max_length=50, default=uuid.uuid4) + # about page registration_closed_text = models.TextField( default="We aren't taking new users at this time. You can find an open " @@ -38,7 +43,7 @@ class SiteSettings(models.Model): privacy_policy = models.TextField(default="Add a privacy policy here.") # registration - allow_registration = models.BooleanField(default=True) + allow_registration = models.BooleanField(default=False) allow_invite_requests = models.BooleanField(default=True) require_confirm_email = models.BooleanField(default=True) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 43e8eb22..8b1f5397 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -32,6 +32,7 @@ {% block head_links %}{% endblock %} +{% block body %}