Fix superuser-creation on fully fresh db. Resolve #3735.
This commit is contained in:
parent
f234298077
commit
53b7ee8a90
1 changed files with 13 additions and 3 deletions
|
|
@ -820,7 +820,7 @@ def start_evennia(pprofiler=False, sprofiler=False):
|
||||||
if response:
|
if response:
|
||||||
_, _, _, _, pinfo, sinfo = response
|
_, _, _, _, pinfo, sinfo = response
|
||||||
_print_info(pinfo, sinfo)
|
_print_info(pinfo, sinfo)
|
||||||
_reactor_stop()
|
_reactor_stop()
|
||||||
|
|
||||||
def _portal_started(*args):
|
def _portal_started(*args):
|
||||||
print(
|
print(
|
||||||
|
|
@ -1460,9 +1460,15 @@ def create_game_directory(dirname):
|
||||||
|
|
||||||
def create_superuser():
|
def create_superuser():
|
||||||
"""
|
"""
|
||||||
Create the superuser account
|
Auto-create the superuser account. Returns `True` if superuser was created.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from evennia.accounts.models import AccountDB
|
||||||
|
|
||||||
|
if AccountDB.objects.filter(is_superuser=True).exists():
|
||||||
|
# if superuser already exists, do nothing here
|
||||||
|
return False
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"\nCreate a superuser below. The superuser is Account #1, the 'owner' "
|
"\nCreate a superuser below. The superuser is Account #1, the 'owner' "
|
||||||
"account of the server. Email is optional and can be empty.\n"
|
"account of the server. Email is optional and can be empty.\n"
|
||||||
|
|
@ -1474,13 +1480,14 @@ def create_superuser():
|
||||||
password = environ.get("EVENNIA_SUPERUSER_PASSWORD")
|
password = environ.get("EVENNIA_SUPERUSER_PASSWORD")
|
||||||
|
|
||||||
if (username is not None) and (password is not None) and len(password) > 0:
|
if (username is not None) and (password is not None) and len(password) > 0:
|
||||||
from evennia.accounts.models import AccountDB
|
|
||||||
|
|
||||||
superuser = AccountDB.objects.create_superuser(username, email, password)
|
superuser = AccountDB.objects.create_superuser(username, email, password)
|
||||||
superuser.save()
|
superuser.save()
|
||||||
else:
|
else:
|
||||||
django.core.management.call_command("createsuperuser", interactive=True)
|
django.core.management.call_command("createsuperuser", interactive=True)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_database(always_return=False):
|
def check_database(always_return=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1547,6 +1554,9 @@ def check_database(always_return=False):
|
||||||
f"Database tables missing: {', '.join(missing_tables)}. "
|
f"Database tables missing: {', '.join(missing_tables)}. "
|
||||||
"Did you remember to run migrations?"
|
"Did you remember to run migrations?"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
create_superuser()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue