This commit is contained in:
Joshua Laymon
2025-08-12 22:07:25 -05:00
parent 2fb9e7c39c
commit 3458501272
24 changed files with 268 additions and 26444 deletions
+12 -24
View File
@@ -1,28 +1,16 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
import os
class Command(BaseCommand):
help = "Create or update initial users from environment variables."
def handle(self, *args, **options):
admin_user = os.getenv("ADMIN_USERNAME")
admin_pass = os.getenv("ADMIN_PASSWORD")
editor_user = os.getenv("USER_USERNAME")
editor_pass = os.getenv("USER_PASSWORD")
if admin_user and admin_pass:
u, created = User.objects.get_or_create(username=admin_user)
u.is_staff = True
u.is_superuser = True
u.set_password(admin_pass)
u.save()
self.stdout.write(self.style.SUCCESS(f"Admin user ensured: {admin_user}"))
if editor_user and editor_pass:
u, created = User.objects.get_or_create(username=editor_user)
u.is_staff = False
u.is_superuser = False
u.set_password(editor_pass)
u.save()
self.stdout.write(self.style.SUCCESS(f"Editor user ensured: {editor_user}"))
help="Ensure initial users from env"
def handle(self,*args,**kwargs):
au=os.getenv("ADMIN_USERNAME"); ap=os.getenv("ADMIN_PASSWORD")
eu=os.getenv("USER_USERNAME"); ep=os.getenv("USER_PASSWORD")
if au and ap:
u,_=User.objects.get_or_create(username=au)
u.is_staff=True; u.is_superuser=True; u.set_password(ap); u.save()
self.stdout.write(self.style.SUCCESS(f"Admin ensured: {au}"))
if eu and ep:
u,_=User.objects.get_or_create(username=eu)
u.is_staff=False; u.is_superuser=False; u.set_password(ep); u.save()
self.stdout.write(self.style.SUCCESS(f"Editor ensured: {eu}"))