image created

This commit is contained in:
2025-01-22 16:33:00 +02:00
parent 9f63572e5e
commit 4b8d075bfe
9 changed files with 115 additions and 3 deletions

20
init_db.py Normal file
View File

@@ -0,0 +1,20 @@
import os
from app import app, db, User, bcrypt
def create_admin_user():
admin_username = os.getenv('ADMIN_USER', 'admin')
admin_password = os.getenv('ADMIN_PASSWORD', 'admin')
hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8')
if not User.query.filter_by(username=admin_username).first():
admin_user = User(username=admin_username, password=hashed_password, role='admin')
db.session.add(admin_user)
db.session.commit()
print(f"Admin user '{admin_username}' created with password '{admin_password}'")
else:
print(f"Admin user '{admin_username}' already exists")
if __name__ == '__main__':
with app.app_context():
db.create_all()
create_admin_user()