diff --git a/Dockerfile b/Dockerfile index 8c18f1be..a69d2b72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get purge -y --auto-remove \ RUN python3 manage.py compilescss \ && python3 manage.py collectstatic --noinput RUN cp -R misc/www /www -RUN mv static /www/static +RUN mv static /www/s # invoke check by default CMD [ "python3", "/neodb/manage.py", "check" ] diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 6e23f630..e0cc4491 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -201,7 +201,7 @@ if os.getenv("NEODB_SSL", "") != "": # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ -STATIC_URL = "/static/" +STATIC_URL = "/s/" STATIC_ROOT = os.environ.get("NEODB_STATIC_ROOT", os.path.join(BASE_DIR, "static/")) STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" @@ -219,7 +219,7 @@ SILENCED_SYSTEM_CHECKS = [ "fields.W344", # Required by takahe: identical table name in different database ] -MEDIA_URL = "/media/" +MEDIA_URL = "/m/" MEDIA_ROOT = os.environ.get("NEODB_MEDIA_ROOT", os.path.join(BASE_DIR, "media/")) SITE_DOMAIN = os.environ.get("NEODB_SITE_DOMAIN", "nicedb.org") diff --git a/misc/nginx.conf.d/neodb.conf b/misc/nginx.conf.d/neodb.conf index 42e8e001..ebb18efa 100644 --- a/misc/nginx.conf.d/neodb.conf +++ b/misc/nginx.conf.d/neodb.conf @@ -12,11 +12,11 @@ server { proxy_pass http://neodb-web:8000; } - location /static/ { + location /s/ { root /www; } - location /media/ { + location /m/ { root /www; } } diff --git a/users/models/user.py b/users/models/user.py index 2531f825..3776353d 100644 --- a/users/models/user.py +++ b/users/models/user.py @@ -3,7 +3,7 @@ import re from functools import cached_property from typing import TYPE_CHECKING -from django.contrib.auth.models import AbstractUser +from django.contrib.auth.models import AbstractUser, BaseUserManager from django.contrib.auth.validators import UnicodeUsernameValidator from django.core.exceptions import ValidationError from django.db import models @@ -48,6 +48,24 @@ class UsernameValidator(UnicodeUsernameValidator): return super().__call__(value) +class UserManager(BaseUserManager): + def create_user(self, username, email, password=None): + Takahe.get_domain() # ensure configuration is complete + user = User.register(username=username, email=email) + return user + + def create_superuser(self, username, email, password=None): + from takahe.models import User as TakaheUser + + Takahe.get_domain() # ensure configuration is complete + user = User.register(username=username, email=email, is_superuser=True) + tu = TakaheUser.objects.get(pk=user.pk, email="@" + username) + tu.admin = True + tu.set_password(password) + tu.save() + return user + + class User(AbstractUser): identity: "APIdentity" preference: "Preference" @@ -113,6 +131,7 @@ class User(AbstractUser): # store the latest read announcement id, # every time user read the announcement update this field read_announcement_index = models.PositiveIntegerField(default=0) + objects = UserManager() class Meta: constraints = [