_csrf_protect. Internal helper function. This docstring was expanded to make future maintenance easier. Returns: Varies.
()
| 1541 | |
| 1542 | def _trusted_device_touch(username: str, fp: str): |
| 1543 | try: |
| 1544 | conn = db_connect() |
| 1545 | conn.execute("UPDATE trusted_devices SET last_used=? WHERE username=? AND device_fp=?", (now_z(), username, fp)) |
| 1546 | conn.commit() |
| 1547 | conn.close() |
| 1548 | except Exception: |
| 1549 | pass |
| 1550 | |
| 1551 | def _issue_trusted_device(username: str, fp: str, approved_by: Optional[str]=None) -> str: |
| 1552 | """Create or rotate a trusted-device token for (username, fp). Returns raw token.""" |
| 1553 | token = secrets.token_urlsafe(32) |
| 1554 | th = _sha256_hex(token) |
| 1555 | conn = db_connect() |
| 1556 | # Upsert (best-effort) |
| 1557 | row = conn.execute("SELECT id FROM trusted_devices WHERE username=? AND device_fp=?", (username, fp)).fetchone() |
| 1558 | if row: |
| 1559 | conn.execute( |
| 1560 | "UPDATE trusted_devices SET token_hash=?, status='approved', approved_by=COALESCE(?, approved_by), created_at=COALESCE(created_at, ?) WHERE id=?", |
| 1561 | (th, approved_by, now_z(), row["id"]) |
| 1562 | ) |
| 1563 | else: |
| 1564 | conn.execute( |
| 1565 | "INSERT INTO trusted_devices(username, device_fp, token_hash, created_at, last_used, approved_by, status) VALUES(?,?,?,?,?,?, 'approved')", |
| 1566 | (username, fp, th, now_z(), now_z(), approved_by) |
| 1567 | ) |
| 1568 | conn.commit() |
| 1569 | conn.close() |
| 1570 | return token |
| 1571 | |
| 1572 | def _admins_list() -> List[str]: |
| 1573 | try: |
| 1574 | conn = db_connect() |
nothing calls this directly
no test coverage detected