mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
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:
9
app.py
9
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,
|
||||
|
||||
Reference in New Issue
Block a user