(rid: int)
| 17564 | try: |
| 17565 | conn = db_connect() |
| 17566 | rows = conn.execute("SELECT username FROM pending_users WHERE status='pending' ORDER BY id ASC").fetchall() |
| 17567 | conn.close() |
| 17568 | for r in rows: |
| 17569 | try: |
| 17570 | PENDING_QUEUE.put_nowait(r["username"]) |
| 17571 | except Exception: |
| 17572 | pass |
| 17573 | except Exception: |
| 17574 | pass |
| 17575 | |
| 17576 | def approval_prompt(username: str): |
| 17577 | """Run an interactive approve/deny prompt in the *main thread*. |
| 17578 | |
| 17579 | Termux/Android terminals can fail to show `input()` prompts reliably when they |
| 17580 | happen inside background threads. This function is meant to be called from |
| 17581 | the main loop so the prompt always appears. |
| 17582 | """ |
| 17583 | if not username: |
| 17584 | return |
| 17585 | try: |
| 17586 | conn = db_connect() |
| 17587 | row = conn.execute("""SELECT username, requested_ip, requested_at, status, pw_hash |
| 17588 | FROM pending_users WHERE username=?""", (username,)).fetchone() |
| 17589 | if not row or row["status"] != "pending": |
| 17590 | conn.close() |
| 17591 | return |
| 17592 | |
| 17593 | sys.stdout.write("\n") |
| 17594 | sys.stdout.flush() |
| 17595 | prompt = (f"[ButSystem] Signup request: '{row['username']}' from {row['requested_ip']} " |
| 17596 | f"at {row['requested_at']} Approve? (y/N): ") |
| 17597 | try: |
| 17598 | ans = input(prompt).strip().lower() |
| 17599 | except EOFError: |
| 17600 | # No TTY / stdin closed. |
| 17601 | ans = "" |
| 17602 | |
| 17603 | if ans == "y": |
| 17604 | conn.execute("INSERT OR IGNORE INTO users(username, pw_hash, is_admin, created_at) VALUES(?,?,0,?)", |
nothing calls this directly
no test coverage detected