Skip to content

Commit 6f1de51

Browse files
committed
fixed admin user generation
1 parent 1be3dcb commit 6f1de51

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

configs.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ def get_sys_exec_root_or_drive():
3737
if not all([algolia_app_id, algolia_api_key]):
3838
print("Application requires 'ALGOLIA_APP_ID' and 'ALGOLIA_API_KEY' for search")
3939

40+
41+
secret_key = os.environ.get('SECRET_KEY')
42+
43+
security_password_hash = 'pbkdf2_sha512'
44+
# Replace this with your own salt.
45+
security_password_salt = os.environ.get('SECURITY_PASSWORD_SALT')
46+
if not all([secret_key, security_password_salt]):
47+
raise KeyError("Keys'SECRET_KEY' and 'SECURITY_PASSWORD_SALT' missing")
48+
49+
4050
index_name = os.environ.get("INDEX_NAME")
4151

4252

@@ -45,12 +55,9 @@ class Config:
4555

4656
SQLALCHEMY_DATABASE_URI = f"postgresql://{pg_user}:{pg_pw}@{pg_host}:5432/{pg_db}"
4757

48-
SECRET_KEY = os.urandom(24)
49-
# Set config values for Flask-Security.
50-
# We're using PBKDF2 with salt.
51-
SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
52-
# Replace this with your own salt.
53-
SECURITY_PASSWORD_SALT = os.urandom(140)
58+
SECRET_KEY = secret_key
59+
SECURITY_PASSWORD_HASH = security_password_hash
60+
SECURITY_PASSWORD_SALT = security_password_salt
5461

5562
ALGOLIA_APP_ID = algolia_app_id
5663
ALGOLIA_API_KEY = algolia_api_key

run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def make_shell_context():
2727
return {'db': db, 'Resource': Resource, 'Category': Category,
2828
'Language': Language, 'User': User, 'Role': Role}
2929

30+
3031
# Create Admin user and role.
3132
@app.before_first_request
3233
def before_first_request():
@@ -44,7 +45,8 @@ def before_first_request():
4445
# In each case, use Flask-Security utility function to encrypt the password.
4546
encrypted_password = utils.encrypt_password(admin_password)
4647
if not user_datastore.get_user(admin_email):
47-
user_datastore.create_user(admin_email, password=encrypted_password)
48+
user_datastore.create_user(email=admin_email,
49+
password=encrypted_password)
4850
# Add more users.
4951

5052
# Commit any database changes; the User and Roles must exist before we

0 commit comments

Comments
 (0)