Raspberry Pi 4 appliance that boots as a WiFi access point and serves a phone-controlled web app for browsing /localmedia and driving video playback out the Pi's HDMI port. - NetworkManager-based AP setup (documented in README) - Flask app + vanilla HTML/JS single-page UI (Control / Playback modes) - mpv persistent daemon (DRM/KMS HDMI output) controlled over JSON IPC - long-lived session-cookie auth - "keep playing" folder auto-advance, including when started mid-folder - systemd units for both mpv and the app, autostart on boot Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
682 B
Python
26 lines
682 B
Python
import hmac
|
|
|
|
from flask import current_app, redirect, request, session, url_for
|
|
|
|
EXEMPT_ENDPOINTS = {"auth.login", "static"}
|
|
|
|
|
|
def check_credentials(username, password):
|
|
cfg = current_app.config
|
|
return hmac.compare_digest(username, cfg["USERNAME"]) and hmac.compare_digest(
|
|
password, cfg["PASSWORD"]
|
|
)
|
|
|
|
|
|
def is_authenticated():
|
|
return bool(session.get("authenticated"))
|
|
|
|
|
|
def register_auth_gate(app):
|
|
@app.before_request
|
|
def _require_login():
|
|
if request.endpoint in EXEMPT_ENDPOINTS or request.endpoint is None:
|
|
return None
|
|
if not is_authenticated():
|
|
return redirect(url_for("auth.login"))
|
|
return None
|