From ef2d9696546feb9b96de97343c927640c24c358d Mon Sep 17 00:00:00 2001 From: Stef Date: Mon, 11 Aug 2025 01:57:31 +0200 Subject: [PATCH] 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. --- app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index a9b4864..c42c394 100644 --- a/app.py +++ b/app.py @@ -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,