Create default admin user if no users exist

Adds logic to automatically create an admin account with default credentials if the user table is empty when the app starts. This ensures there is always an admin user available for initial setup.
This commit is contained in:
2025-08-11 01:57:31 +02:00
parent 2f89097219
commit ef2d969654

9
app.py
View File

@@ -31,8 +31,6 @@ app.register_blueprint(add_meal_bp)
# Routes
def default_return(next_page: Optional[str] = None):
return redirect(url_for("user.daily_log"))
if next_page:
@@ -81,8 +79,13 @@ def scan():
# Run
if __name__ == "__main__":
# If there are no users, create admin account
if User.query.count() == 0:
admin = User(username="admin", password="admin", is_admin=True)
db.session.add(admin)
db.session.commit()
app.run(
host="0.0.0.0",
port=80,