Update
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
import os
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **kwargs):
|
||||
admin_user = os.getenv("INIT_ADMIN_USERNAME")
|
||||
admin_pass = os.getenv("INIT_ADMIN_PASSWORD")
|
||||
editor_user = os.getenv("INIT_EDITOR_USERNAME")
|
||||
editor_pass = os.getenv("INIT_EDITOR_PASSWORD")
|
||||
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
|
||||
if admin_pass:
|
||||
u.set_password(admin_pass)
|
||||
u.set_password(admin_pass)
|
||||
u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Admin ready: {admin_user}"))
|
||||
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
|
||||
if editor_pass:
|
||||
u.set_password(editor_pass)
|
||||
u.set_password(editor_pass)
|
||||
u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor ready: {editor_user}"))
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor user ensured: {editor_user}"))
|
||||
|
||||
Reference in New Issue
Block a user