]> git.parisson.com Git - timeside.git/commitdiff
Add default admin user at startup
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 12 Mar 2015 15:59:42 +0000 (16:59 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 12 Mar 2015 15:59:42 +0000 (16:59 +0100)
examples/deploy/start_app.sh
timeside/server/management/commands/timeside-create-admin-user.py [new file with mode: 0644]

index d5c674d82ff80c13381e14397f2006f589d1c6aa..f977fd232cd4fc3987942189c78aaad4909163a9 100644 (file)
@@ -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 (file)
index 0000000..e6ccdff
--- /dev/null
@@ -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'