From 5fce90eed13c443ad8531b928ee3ad3a4e88beeb Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 12 Mar 2015 16:59:42 +0100 Subject: [PATCH] Add default admin user at startup --- examples/deploy/start_app.sh | 1 + .../commands/timeside-create-admin-user.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 timeside/server/management/commands/timeside-create-admin-user.py diff --git a/examples/deploy/start_app.sh b/examples/deploy/start_app.sh index d5c674d..f977fd2 100644 --- a/examples/deploy/start_app.sh +++ b/examples/deploy/start_app.sh @@ -11,6 +11,7 @@ app_static_dir=$app_dir'timeside/player/static/' python $manage syncdb --noinput python $manage migrate --noinput python $manage collectstatic --noinput +python $manage timeside-create-admin-user # static files auto update pip install watchdog diff --git a/timeside/server/management/commands/timeside-create-admin-user.py b/timeside/server/management/commands/timeside-create-admin-user.py new file mode 100644 index 0000000..e6ccdff --- /dev/null +++ b/timeside/server/management/commands/timeside-create-admin-user.py @@ -0,0 +1,24 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User + + +class Command(BaseCommand): + help = """Create a default admin user if it doesn't exists. + you SHOULD change the password and the email afterwards!""" + + username = 'admin' + password = 'admin' + email = 'root@example.com' + + def handle(self, *args, **options): + admin = User.objects.filter(username=self.username) + if not admin: + user = User(username=self.username) + user.set_password(self.password) + user.email = self.email + user.is_superuser = True + user.is_staff = True + user.save() + print 'User "'+ self.username + '" created' -- 2.39.5