Parcourir la source

Automatically create super user on django

Jérôme BUISINE il y a 4 ans
Parent
commit
42ffcdd4bd
6 fichiers modifiés avec 28 ajouts et 2 suppressions
  1. 4 1
      .gitignore
  2. 3 0
      Dockerfile
  3. 10 0
      README.md
  4. 0 1
      ThesisWebExpeDjango/settings.py
  5. 6 0
      create_admin.sh
  6. 5 0
      credentials example.json

+ 4 - 1
.gitignore

@@ -116,4 +116,7 @@ GitHub.sublime-settings
 .history
 
 # exclude media folder
-media
+media
+
+# credentials
+credentials.json

+ 3 - 0
Dockerfile

@@ -21,4 +21,7 @@ RUN echo $WEBEXPE_PREFIX_URL
 RUN WEBEXPE_PREFIX_URL=$WEBEXPE_PREFIX_URL
 RUN WEB_API_PREFIX_URL=$WEB_API_PREFIX_URL
 
+# create super user admin automatically
+RUN bash create_admin.sh
+
 CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

+ 10 - 0
README.md

@@ -22,6 +22,11 @@ Initialize the database with the following command :
 python manage.py migrate
 ```
 
+Add your own super user admin credentials:
+```
+cp credentials.example.json credentials.json
+```
+
 #### Run server
 
 Run the server :
@@ -38,6 +43,11 @@ python manage.py runserver 8080
 
 ### 2. Using docker (recommended)
 
+First, you need to add your own user admin credentials if you wished:
+```
+cp credentials.example.json credentials.json
+```
+
 You can use make commands:
 
 ```

+ 0 - 1
ThesisWebExpeDjango/settings.py

@@ -27,7 +27,6 @@ DEBUG = True
 
 ALLOWED_HOSTS = ["diran.univ-littoral.fr", "localhost", "127.0.0.1"]
 
-
 # Application definition
 
 INSTALLED_APPS = [

+ 6 - 0
create_admin.sh

@@ -0,0 +1,6 @@
+#! /bin/bash
+
+username=$(cat credentials.json | python -c "import sys, json; print(json.load(sys.stdin)['username'])")
+password=$(cat credentials.json | python -c "import sys, json; print(json.load(sys.stdin)['password'])")
+email=$(cat credentials.json | python -c "import sys, json; print(json.load(sys.stdin)['email'])")
+echo "from django.contrib.auth.models import User; User.objects.create_superuser('${username}', '${email}', '${password}')" | python manage.py shell

+ 5 - 0
credentials example.json

@@ -0,0 +1,5 @@
+{
+    "username":"username",
+    "email":"",
+    "password":"pass"
+}