list_dir_entries. Route handler or application helper. This docstring was expanded to make future maintenance easier. Args: username: Parameter. rel: Parameter. sort: Parameter. order: Parameter. Returns: Varies.
(username: str, rel: str, sort: str, order: str)
| 11482 | row = conn.execute("SELECT 1 FROM trusted_devices WHERE username=? AND device_fp=? AND status='approved' LIMIT 1", (username, fp)).fetchone() |
| 11483 | conn.close() |
| 11484 | if row: |
| 11485 | flash(_("This device is already approved for auto‑login.")) |
| 11486 | return resp |
| 11487 | except Exception: |
| 11488 | pass |
| 11489 | |
| 11490 | ip = _client_ip() or "?" |
| 11491 | ua = (request.headers.get("User-Agent") or "")[:500] |
| 11492 | try: |
| 11493 | conn = db_connect() |
| 11494 | # avoid duplicates: keep most recent request |
| 11495 | conn.execute( |
| 11496 | "INSERT INTO device_access_requests(username, device_fp, requested_ip, user_agent, requested_at, status) VALUES(?,?,?,?,?, 'pending')", |
| 11497 | (username, fp, ip, ua, now_z()) |
| 11498 | ) |
| 11499 | conn.commit() |
| 11500 | conn.close() |
| 11501 | flash(_("Request sent to admin.")) |
| 11502 | except Exception: |
| 11503 | flash(_("Request failed. Please try again.")) |
| 11504 | |
| 11505 | return resp |
| 11506 | |
| 11507 | # GET: show latest status for this device fp (if any) |
| 11508 | try: |
| 11509 | if fp: |
| 11510 | conn = db_connect() |
| 11511 | row = conn.execute( |
| 11512 | "SELECT status FROM device_access_requests WHERE device_fp=? ORDER BY id DESC LIMIT 1", |
| 11513 | (fp,) |
| 11514 | ).fetchone() |
| 11515 | conn.close() |
| 11516 | if row: |
| 11517 | status = row["status"] |
| 11518 | except Exception: |
| 11519 | status = None |
| 11520 | |
| 11521 | resp = render_template("device_access.html", title=_("Device auto‑login"), admins=admins, status=status) |
| 11522 | return resp |
| 11523 | |
| 11524 | @app.route("/device_access/poll") |
| 11525 | def device_access_poll(): |
| 11526 | """Client polls this endpoint for approval. |
| 11527 | When approved, it issues a trusted device token cookie and logs the user in (if 2FA is not enabled). |
| 11528 | """ |
| 11529 | if is_logged_in(): |
| 11530 | return jsonify({"ok": True, "status": "approved", "logged_in": True}) |
| 11531 | fp = (request.cookies.get(DEVICE_FP_COOKIE) or "").strip() |
| 11532 | if not fp: |
| 11533 | return jsonify({"ok": True, "status": "none", "logged_in": False}) |
| 11534 | |
| 11535 | conn = db_connect() |
| 11536 | row = conn.execute( |
| 11537 | "SELECT id, username, status, approved_by FROM device_access_requests WHERE device_fp=? ORDER BY id DESC LIMIT 1", |
| 11538 | (fp,) |
| 11539 | ).fetchone() |
| 11540 | conn.close() |
| 11541 | if not row: |
no test coverage detected