diff --git a/README.md b/README.md
index b27719d..b283416 100644
--- a/README.md
+++ b/README.md
@@ -58,13 +58,7 @@ By default, the `docker-compose.yml` will use the latest image from GHCR. Howeve
docker compose -f docker/docker-compose.yml up
```
-5. To create an admin user, run the following command and follow the prompts:
-
-```
-docker compose -f docker/docker-compose.yml exec web python manage.py createsuperuser
-```
-
-6. After creating the admin user, you will be able to log into the site using the credentials you entered.
+5. Access the site on the configured port. You will be asked to setup an admin user when you first visit the site.
### Using Postgresql
@@ -80,7 +74,7 @@ These instructions are for setting up the project in development mode which may
1. Download or clone this repository.
2. Make a copy of the `.env EXAMPLE` file and name it `.env.dev`. In your new copy, make sure `DEBUG` is set to 1, and change any values that are set to `CHANGEME` to the appropriate values for your development environment.
-3. In the .env.dev file, add values for the following variables: `DJANGO_SUPERUSER_EMAIL` and `DJANGO_SUPERUSER_PASSWORD`. These will be used to create an admin user when the containers are started. For example:
+3. (Optional) In the .env.dev file, add values for the following variables: `DJANGO_SUPERUSER_EMAIL` and `DJANGO_SUPERUSER_PASSWORD`. These will be used to create an admin user when the containers are started. For example:
```
DJANGO_SUPERUSER_EMAIL=admin@mydomain.com
@@ -93,6 +87,6 @@ DJANGO_SUPERUSER_PASSWORD=CHANGEME
docker compose -f docker/dev/docker-compose.dev.yml up --build
```
-4. Once the containers are running, you should be able to access the site in your web browser at `127.0.0.1:8000`. By default, the admin user will automatically be created and you will be able to log in using the credentials you entered in the .env.dev file.
+4. Once the containers are running, you should be able to access the site in your web browser at `127.0.0.1:8000`. If you added environment variables for the superuser, you should be able to login with those credentials. Otherwise you will be prompted to create a super user every time to start up the server.
If you would like contribute to this project, please read the [contributing guidelines](CONTRIBUTING.md) for more information.
diff --git a/shifter/requirements.txt b/shifter/requirements.txt
index fc947e8..ca492ee 100644
--- a/shifter/requirements.txt
+++ b/shifter/requirements.txt
@@ -5,4 +5,5 @@ gunicorn==23.0.0
psycopg==3.2.3
psycopg-binary==3.2.3
sqlparse==0.5.1
-typing_extensions==4.12.2
\ No newline at end of file
+typing_extensions==4.12.2
+tblib==3.0.0
\ No newline at end of file
diff --git a/shifter/shifter/settings.py b/shifter/shifter/settings.py
index 77a1b5b..44fd9df 100644
--- a/shifter/shifter/settings.py
+++ b/shifter/shifter/settings.py
@@ -64,6 +64,7 @@
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
+ "shifter_auth.middleware.ensure_first_time_setup_completed",
"shifter_auth.middleware.ensure_password_changed",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
diff --git a/shifter/shifter_auth/middleware.py b/shifter/shifter_auth/middleware.py
index 53ac12f..a7c903e 100644
--- a/shifter/shifter_auth/middleware.py
+++ b/shifter/shifter_auth/middleware.py
@@ -1,7 +1,13 @@
+from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.urls import reverse
+def is_first_time_setup_required():
+ User = get_user_model()
+ return User.objects.count() == 0
+
+
def ensure_password_changed(get_response):
CHANGE_PASSWORD_URL = "shifter_auth:settings"
@@ -21,3 +27,18 @@ def middleware(request):
return response
return middleware
+
+
+def ensure_first_time_setup_completed(get_response):
+ FIRST_TIME_SETUP_URL = "shifter_auth:first-time-setup"
+
+ def middleware(request):
+ if is_first_time_setup_required() and request.path != reverse(
+ FIRST_TIME_SETUP_URL
+ ):
+ return redirect(FIRST_TIME_SETUP_URL)
+
+ response = get_response(request)
+ return response
+
+ return middleware
diff --git a/shifter/shifter_auth/templates/shifter_auth/setup.html b/shifter/shifter_auth/templates/shifter_auth/setup.html
new file mode 100644
index 0000000..7b58218
--- /dev/null
+++ b/shifter/shifter_auth/templates/shifter_auth/setup.html
@@ -0,0 +1,43 @@
+{% extends 'base.html' %}
+
+{% block title %}
First Time Setup | Shifter{% endblock %}
+
+{% block content %}
+
+
+
First Time Setup
+
+
+
Welcome to Shifter!
+
First you need to create an admin user. Admins are able to create accounts for other people, and can be used as a regular user.