File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -275,23 +275,26 @@ def handle_exception(error):
275275 # Create all tables
276276 db .create_all ()
277277
278- # Create default admin user if it doesn't exist
279- admin_user = User .query .filter_by (username = 'admin' ).first ()
280- if not admin_user :
278+ # Create default admin user only if no administrators exist
279+ admin_count = User .query .filter_by (is_admin = True ).count ()
280+ if admin_count == 0 :
281+ # No administrators exist, create default admin user
281282 admin_user = User (username = 'admin' , is_admin = True )
282- admin_user .set_password ('admin ' ) # CHANGE THIS IN PRODUCTION!
283+ admin_user .set_password ('changeme ' ) # Default password
283284 db .session .add (admin_user )
284285 try :
285286 db .session .commit ()
286287 print ("=" * 50 )
287- print ("Admin user created!" )
288+ print ("Default admin user created!" )
288289 print ("Username: admin" )
289- print ("Password: admin " )
290+ print ("Password: changeme " )
290291 print ("PLEASE CHANGE THIS PASSWORD IMMEDIATELY!" )
291292 print ("=" * 50 )
292293 except Exception as e :
293294 print (f"Error creating admin user: { e } " )
294295 db .session .rollback ()
296+ else :
297+ print (f"Found { admin_count } administrator(s) - skipping default admin creation" )
295298
296299 # ===== Additional App Configuration =====
297300
You can’t perform that action at this time.
0 commit comments