Browse Source

Adiciona checagem de password e usuario admin existente

pull/942/merge
Edward Ribeiro 8 years ago
parent
commit
c0ff18e4d8
  1. 4
      create_admin.py
  2. 24
      start.sh

4
create_admin.py

@ -13,11 +13,11 @@ def create_superuser():
email = os.environ['ADMIN_EMAIL'] if 'ADMIN_EMAIL' in os.environ else ''
if User.objects.filter(username=username).exists():
# print("[SUPERUSER] User %s already exists. Exiting without change." % username)
print("[SUPERUSER] User %s already exists. Exiting without change." % username)
sys.exit('ADMIN_USER_EXISTS')
else:
if not password:
# print("[SUPERUSER] Environment variable $ADMIN_PASSWORD for user %s was not set. Leaving..." % username)
print("[SUPERUSER] Environment variable $ADMIN_PASSWORD for user %s was not set. Leaving..." % username)
sys.exit('MISSING_ADMIN_PASSWORD')
print("[SUPERUSER] Creating superuser...")

24
start.sh

@ -40,8 +40,6 @@ create_env() {
create_env
# # python3 gen-env.py
python3 manage.py bower install
/bin/sh busy-wait.sh $DATABASE_URL
@ -50,18 +48,22 @@ python3 manage.py migrate
python3 manage.py collectstatic --no-input
python3 manage.py rebuild_index --noinput
user_created=$(python3 create_admin.py)
user_created=$(python3 create_admin.py 2>&1)
cmd=$(echo $user_created | grep 'ADMIN_USER_EXISTS')
user_exists=$?
echo $user_created
cmd=$(echo $user_created | grep 'MISSING_ADMIN_PASSWORD')
lack_pwd=$?
#if [ $user_created -eq "ADMIN_USER_EXISTS" ]; then
# echo "[SUPERUSER CREATION] User admin already exists. Not creating"
#fi
if [ $user_exists -eq 0 ]; then
echo "[SUPERUSER CREATION] User admin already exists. Not creating"
fi
#if [ $user_created -eq "MISSING_ADMIN_PASSWORD" ]; then
# echo "[SUPERUSER] Environment variable $ADMIN_PASSWORD for superuser admin was not set. Leaving container"
# return -1 # TODO: Uncomment when in finally in prod.
#fi
if [ $lack_pwd -eq 0 ]; then
echo "[SUPERUSER] Environment variable $ADMIN_PASSWORD for superuser admin was not set. Leaving container"
# return -1
fi
/bin/sh gunicorn_start.sh no-venv

Loading…
Cancel
Save