feat: create default admin user when initializing the database

This commit is contained in:
Manuel Weiser 2024-09-02 10:45:58 +02:00
parent 7047f7c7e8
commit 78c13051d0

View File

@ -1,6 +1,7 @@
import sqlite3 import sqlite3
import os import os
from flask import current_app from flask import current_app
from werkzeug.security import generate_password_hash
def init_db(): def init_db():
db_path = os.path.join(current_app.instance_path, 'games.db') db_path = os.path.join(current_app.instance_path, 'games.db')
@ -30,5 +31,12 @@ def init_db():
) )
''') ''')
# Standardbenutzer erstellen
hashed_password = generate_password_hash("admin")
cursor.execute('''
INSERT OR IGNORE INTO users (username, password, role)
VALUES (?, ?, ?)
''', ("admin", hashed_password, "admin"))
conn.commit() conn.commit()
conn.close() conn.close()