Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- PLANS.md +5 -0
- README.md +1 -0
- TASKS.md +4 -1
- app/rooms_store.py +98 -2
- app/routes/rooms.py +95 -0
- docs/TROUBLESHOOTING.md +5 -0
- static/dashboard.html +25 -11
- static/dashboard.js +133 -0
- static/index.html +46 -0
- static/login.js +110 -2
- tests/test_security_gates.py +5 -0
PLANS.md
CHANGED
|
@@ -103,3 +103,8 @@ Note: see `docs/PASSWORD_MANAGER_SCOPE.md` for the current (non-vault) stance an
|
|
| 103 |
|
| 104 |
- Support GitHub token auth via HF Secrets (`GITHUB_TOKEN`/`GITHUB_PAT`) and document it in `.env.example`.
|
| 105 |
- Merge Aunomous mode and chat mode to single chat UI.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
- Support GitHub token auth via HF Secrets (`GITHUB_TOKEN`/`GITHUB_PAT`) and document it in `.env.example`.
|
| 105 |
- Merge Aunomous mode and chat mode to single chat UI.
|
| 106 |
+
- Include password reset by email too.
|
| 107 |
+
- Also include one password manager/passowrd vault too.
|
| 108 |
+
- Get started on landing page should go to a documentaion page.
|
| 109 |
+
- Open App and Login should point to login page.
|
| 110 |
+
- Provider setting on path /app should be only on settings page.
|
README.md
CHANGED
|
@@ -73,6 +73,7 @@ This repo includes a manual workflow at `.github/workflows/codex-autofix.yml`.
|
|
| 73 |
- **Secrets**: don’t hardcode API keys in source. GitHub push protection will block pushes containing tokens.
|
| 74 |
- **Security**: the web terminal and agent/Codex endpoints are gated by Supabase auth. Keep Supabase configured and avoid exposing execution features publicly without auth.
|
| 75 |
- **Terminal PTY**: the host/container must have PTY devices (`/dev/pts`) available for interactive terminals.
|
|
|
|
| 76 |
- **Codex login (Hugging Face Spaces/web terminal)**: Spaces expose a single port, so localhost callback URLs (like `http://localhost:1455/auth/callback?...`) won’t work; use device auth: `codex login --device-auth` (alias: `codex-login`).
|
| 77 |
- **Codex login persistence (Spaces)**: on startup the container will use `/data/.codex` (if available) for `~/.codex`, so device-auth stays logged in across restarts.
|
| 78 |
- **Codex tokens (Spaces Secrets)**: if you already have tokens, set `CODEX_ID_TOKEN`, `CODEX_ACCESS_TOKEN`, `CODEX_REFRESH_TOKEN` (and optionally `CODEX_ACCOUNT_ID`) as Spaces Secrets; the container will write `~/.codex/.auth.json` (and `~/.codex/auth.json`) on startup.
|
|
|
|
| 73 |
- **Secrets**: don’t hardcode API keys in source. GitHub push protection will block pushes containing tokens.
|
| 74 |
- **Security**: the web terminal and agent/Codex endpoints are gated by Supabase auth. Keep Supabase configured and avoid exposing execution features publicly without auth.
|
| 75 |
- **Terminal PTY**: the host/container must have PTY devices (`/dev/pts`) available for interactive terminals.
|
| 76 |
+
- **Password reset**: the Login page supports Supabase password recovery links. Ensure your Supabase redirect URLs include `/login`.
|
| 77 |
- **Codex login (Hugging Face Spaces/web terminal)**: Spaces expose a single port, so localhost callback URLs (like `http://localhost:1455/auth/callback?...`) won’t work; use device auth: `codex login --device-auth` (alias: `codex-login`).
|
| 78 |
- **Codex login persistence (Spaces)**: on startup the container will use `/data/.codex` (if available) for `~/.codex`, so device-auth stays logged in across restarts.
|
| 79 |
- **Codex tokens (Spaces Secrets)**: if you already have tokens, set `CODEX_ID_TOKEN`, `CODEX_ACCESS_TOKEN`, `CODEX_REFRESH_TOKEN` (and optionally `CODEX_ACCOUNT_ID`) as Spaces Secrets; the container will write `~/.codex/.auth.json` (and `~/.codex/auth.json`) on startup.
|
TASKS.md
CHANGED
|
@@ -56,7 +56,7 @@ Legend:
|
|
| 56 |
- [x] Jobs UI (MVP: start/cancel/list crawl jobs).
|
| 57 |
|
| 58 |
## P3 — P2P pubsub chat + account manager
|
| 59 |
-
- [
|
| 60 |
- [~] Transport: WebRTC DataChannel + signaling, with server pubsub fallback.
|
| 61 |
- [~] UX: rooms, presence, delivery status, network mode indicators.
|
| 62 |
|
|
@@ -67,3 +67,6 @@ Legend:
|
|
| 67 |
|
| 68 |
## P2/P3 — UI consolidation (nice-to-have)
|
| 69 |
- [ ] Merge Autonomous mode and chat mode to a single chat UI.
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
- [x] Jobs UI (MVP: start/cancel/list crawl jobs).
|
| 57 |
|
| 58 |
## P3 — P2P pubsub chat + account manager
|
| 59 |
+
- [~] Account manager: identities/devices, memberships, permissions, moderation.
|
| 60 |
- [~] Transport: WebRTC DataChannel + signaling, with server pubsub fallback.
|
| 61 |
- [~] UX: rooms, presence, delivery status, network mode indicators.
|
| 62 |
|
|
|
|
| 67 |
|
| 68 |
## P2/P3 — UI consolidation (nice-to-have)
|
| 69 |
- [ ] Merge Autonomous mode and chat mode to a single chat UI.
|
| 70 |
+
|
| 71 |
+
## P2 — Auth UX
|
| 72 |
+
- [x] Password reset by email (Supabase recovery flow).
|
app/rooms_store.py
CHANGED
|
@@ -38,6 +38,8 @@ class Room:
|
|
| 38 |
created_at: str
|
| 39 |
owner_user_id: str
|
| 40 |
members: set[str] = field(default_factory=set)
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def to_public(self, *, for_user_id: str) -> dict[str, Any]:
|
| 43 |
return {
|
|
@@ -47,6 +49,7 @@ class Room:
|
|
| 47 |
"ownerUserId": self.owner_user_id,
|
| 48 |
"memberCount": len(self.members),
|
| 49 |
"isMember": for_user_id in self.members,
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
|
|
@@ -82,9 +85,26 @@ class RoomsStore:
|
|
| 82 |
created_at = str(r.get("createdAt") or _now_iso()).strip()
|
| 83 |
owner = str(r.get("ownerUserId") or "").strip()
|
| 84 |
members = set(str(x) for x in (r.get("members") or []) if str(x).strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
if not rid or not owner:
|
| 86 |
continue
|
| 87 |
-
self._rooms[rid] = Room(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def _save(self) -> None:
|
| 90 |
path = _rooms_path()
|
|
@@ -98,6 +118,8 @@ class RoomsStore:
|
|
| 98 |
"createdAt": r.created_at,
|
| 99 |
"ownerUserId": r.owner_user_id,
|
| 100 |
"members": sorted(r.members),
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
)
|
| 103 |
payload = {"version": 1, "rooms": rooms}
|
|
@@ -119,7 +141,14 @@ class RoomsStore:
|
|
| 119 |
raise ValueError("user_id required")
|
| 120 |
room_id = str(uuid.uuid4())
|
| 121 |
nm = (name or "Room").strip()[:80] or "Room"
|
| 122 |
-
room = Room(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
async with self._lock:
|
| 124 |
self._rooms[room_id] = room
|
| 125 |
self._save()
|
|
@@ -139,7 +168,11 @@ class RoomsStore:
|
|
| 139 |
room = self._rooms.get(rid)
|
| 140 |
if not room:
|
| 141 |
return None
|
|
|
|
|
|
|
| 142 |
room.members.add(uid)
|
|
|
|
|
|
|
| 143 |
self._save()
|
| 144 |
return room
|
| 145 |
|
|
@@ -153,12 +186,75 @@ class RoomsStore:
|
|
| 153 |
if not room:
|
| 154 |
return False
|
| 155 |
room.members.discard(uid)
|
|
|
|
| 156 |
# Owner-less or empty rooms are pruned.
|
| 157 |
if not room.members or room.owner_user_id not in room.members:
|
| 158 |
self._rooms.pop(rid, None)
|
| 159 |
self._save()
|
| 160 |
return True
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
async def append_message(self, *, room_id: str, message: dict[str, Any]) -> None:
|
| 163 |
rid = str(room_id or "").strip()
|
| 164 |
if not rid:
|
|
|
|
| 38 |
created_at: str
|
| 39 |
owner_user_id: str
|
| 40 |
members: set[str] = field(default_factory=set)
|
| 41 |
+
roles: dict[str, str] = field(default_factory=dict) # user_id -> role
|
| 42 |
+
banned: set[str] = field(default_factory=set) # user_id
|
| 43 |
|
| 44 |
def to_public(self, *, for_user_id: str) -> dict[str, Any]:
|
| 45 |
return {
|
|
|
|
| 49 |
"ownerUserId": self.owner_user_id,
|
| 50 |
"memberCount": len(self.members),
|
| 51 |
"isMember": for_user_id in self.members,
|
| 52 |
+
"myRole": self.roles.get(for_user_id) if for_user_id in self.members else None,
|
| 53 |
}
|
| 54 |
|
| 55 |
|
|
|
|
| 85 |
created_at = str(r.get("createdAt") or _now_iso()).strip()
|
| 86 |
owner = str(r.get("ownerUserId") or "").strip()
|
| 87 |
members = set(str(x) for x in (r.get("members") or []) if str(x).strip())
|
| 88 |
+
roles_raw = r.get("roles") if isinstance(r, dict) else None
|
| 89 |
+
roles: dict[str, str] = {}
|
| 90 |
+
if isinstance(roles_raw, dict):
|
| 91 |
+
for k, v in roles_raw.items():
|
| 92 |
+
uid = str(k).strip()
|
| 93 |
+
role = str(v).strip().lower()
|
| 94 |
+
if uid and role:
|
| 95 |
+
roles[uid] = role
|
| 96 |
+
banned = set(str(x) for x in (r.get("banned") or []) if str(x).strip())
|
| 97 |
if not rid or not owner:
|
| 98 |
continue
|
| 99 |
+
self._rooms[rid] = Room(
|
| 100 |
+
id=rid,
|
| 101 |
+
name=name,
|
| 102 |
+
created_at=created_at,
|
| 103 |
+
owner_user_id=owner,
|
| 104 |
+
members=members,
|
| 105 |
+
roles=roles,
|
| 106 |
+
banned=banned,
|
| 107 |
+
)
|
| 108 |
|
| 109 |
def _save(self) -> None:
|
| 110 |
path = _rooms_path()
|
|
|
|
| 118 |
"createdAt": r.created_at,
|
| 119 |
"ownerUserId": r.owner_user_id,
|
| 120 |
"members": sorted(r.members),
|
| 121 |
+
"roles": r.roles,
|
| 122 |
+
"banned": sorted(r.banned),
|
| 123 |
}
|
| 124 |
)
|
| 125 |
payload = {"version": 1, "rooms": rooms}
|
|
|
|
| 141 |
raise ValueError("user_id required")
|
| 142 |
room_id = str(uuid.uuid4())
|
| 143 |
nm = (name or "Room").strip()[:80] or "Room"
|
| 144 |
+
room = Room(
|
| 145 |
+
id=room_id,
|
| 146 |
+
name=nm,
|
| 147 |
+
created_at=_now_iso(),
|
| 148 |
+
owner_user_id=uid,
|
| 149 |
+
members={uid},
|
| 150 |
+
roles={uid: "owner"},
|
| 151 |
+
)
|
| 152 |
async with self._lock:
|
| 153 |
self._rooms[room_id] = room
|
| 154 |
self._save()
|
|
|
|
| 168 |
room = self._rooms.get(rid)
|
| 169 |
if not room:
|
| 170 |
return None
|
| 171 |
+
if uid in room.banned:
|
| 172 |
+
return None
|
| 173 |
room.members.add(uid)
|
| 174 |
+
if uid not in room.roles:
|
| 175 |
+
room.roles[uid] = "member"
|
| 176 |
self._save()
|
| 177 |
return room
|
| 178 |
|
|
|
|
| 186 |
if not room:
|
| 187 |
return False
|
| 188 |
room.members.discard(uid)
|
| 189 |
+
room.roles.pop(uid, None)
|
| 190 |
# Owner-less or empty rooms are pruned.
|
| 191 |
if not room.members or room.owner_user_id not in room.members:
|
| 192 |
self._rooms.pop(rid, None)
|
| 193 |
self._save()
|
| 194 |
return True
|
| 195 |
|
| 196 |
+
async def list_members(self, *, room_id: str) -> list[dict[str, Any]] | None:
|
| 197 |
+
rid = str(room_id or "").strip()
|
| 198 |
+
async with self._lock:
|
| 199 |
+
room = self._rooms.get(rid)
|
| 200 |
+
if not room:
|
| 201 |
+
return None
|
| 202 |
+
members = []
|
| 203 |
+
for uid in sorted(room.members):
|
| 204 |
+
members.append({"userId": uid, "role": room.roles.get(uid, "member")})
|
| 205 |
+
return members
|
| 206 |
+
|
| 207 |
+
async def set_role(self, *, room_id: str, user_id: str, role: str) -> bool:
|
| 208 |
+
rid = str(room_id or "").strip()
|
| 209 |
+
uid = str(user_id or "").strip()
|
| 210 |
+
r = str(role or "").strip().lower()
|
| 211 |
+
if not rid or not uid:
|
| 212 |
+
return False
|
| 213 |
+
if r not in {"owner", "moderator", "member"}:
|
| 214 |
+
return False
|
| 215 |
+
async with self._lock:
|
| 216 |
+
room = self._rooms.get(rid)
|
| 217 |
+
if not room or uid not in room.members:
|
| 218 |
+
return False
|
| 219 |
+
room.roles[uid] = r
|
| 220 |
+
if r == "owner":
|
| 221 |
+
room.owner_user_id = uid
|
| 222 |
+
self._save()
|
| 223 |
+
return True
|
| 224 |
+
|
| 225 |
+
async def kick_member(self, *, room_id: str, user_id: str) -> bool:
|
| 226 |
+
rid = str(room_id or "").strip()
|
| 227 |
+
uid = str(user_id or "").strip()
|
| 228 |
+
if not rid or not uid:
|
| 229 |
+
return False
|
| 230 |
+
async with self._lock:
|
| 231 |
+
room = self._rooms.get(rid)
|
| 232 |
+
if not room:
|
| 233 |
+
return False
|
| 234 |
+
if uid == room.owner_user_id:
|
| 235 |
+
return False
|
| 236 |
+
room.members.discard(uid)
|
| 237 |
+
room.roles.pop(uid, None)
|
| 238 |
+
self._save()
|
| 239 |
+
return True
|
| 240 |
+
|
| 241 |
+
async def ban_member(self, *, room_id: str, user_id: str) -> bool:
|
| 242 |
+
rid = str(room_id or "").strip()
|
| 243 |
+
uid = str(user_id or "").strip()
|
| 244 |
+
if not rid or not uid:
|
| 245 |
+
return False
|
| 246 |
+
async with self._lock:
|
| 247 |
+
room = self._rooms.get(rid)
|
| 248 |
+
if not room:
|
| 249 |
+
return False
|
| 250 |
+
if uid == room.owner_user_id:
|
| 251 |
+
return False
|
| 252 |
+
room.banned.add(uid)
|
| 253 |
+
room.members.discard(uid)
|
| 254 |
+
room.roles.pop(uid, None)
|
| 255 |
+
self._save()
|
| 256 |
+
return True
|
| 257 |
+
|
| 258 |
async def append_message(self, *, room_id: str, message: dict[str, Any]) -> None:
|
| 259 |
rid = str(room_id or "").strip()
|
| 260 |
if not rid:
|
app/routes/rooms.py
CHANGED
|
@@ -76,6 +76,9 @@ async def join_room(body: dict[str, Any], http_request: Request):
|
|
| 76 |
if not room_id:
|
| 77 |
raise HTTPException(status_code=400, detail={"code": "invalid_request", "message": "roomId is required"})
|
| 78 |
store: RoomsStore = http_request.app.state.rooms_store
|
|
|
|
|
|
|
|
|
|
| 79 |
room = await store.join_room(room_id=room_id, user_id=user_id)
|
| 80 |
if not room:
|
| 81 |
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
|
@@ -109,6 +112,93 @@ async def room_messages(room_id: str, http_request: Request, limit: int = 50):
|
|
| 109 |
return {"messages": messages}
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
@router.get("/api/rooms/{room_id}/peers")
|
| 113 |
async def room_peers(room_id: str, http_request: Request):
|
| 114 |
if not feature_enabled("rooms"):
|
|
@@ -166,6 +256,11 @@ async def websocket_rooms(websocket: WebSocket):
|
|
| 166 |
|
| 167 |
user_id = str(user.get("id") or "")
|
| 168 |
store: RoomsStore = websocket.app.state.rooms_store
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
room = await store.join_room(room_id=room_id, user_id=user_id)
|
| 170 |
if not room:
|
| 171 |
await websocket.send_text(_ws_json({"type": "error", "message": "unknown_room"}))
|
|
|
|
| 76 |
if not room_id:
|
| 77 |
raise HTTPException(status_code=400, detail={"code": "invalid_request", "message": "roomId is required"})
|
| 78 |
store: RoomsStore = http_request.app.state.rooms_store
|
| 79 |
+
room = await store.get_room(room_id)
|
| 80 |
+
if room and user_id in room.banned:
|
| 81 |
+
raise HTTPException(status_code=403, detail={"code": "banned", "message": "You are banned from this room"})
|
| 82 |
room = await store.join_room(room_id=room_id, user_id=user_id)
|
| 83 |
if not room:
|
| 84 |
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
|
|
|
| 112 |
return {"messages": messages}
|
| 113 |
|
| 114 |
|
| 115 |
+
@router.get("/api/rooms/{room_id}/members")
|
| 116 |
+
async def room_members(room_id: str, http_request: Request):
|
| 117 |
+
if not feature_enabled("rooms"):
|
| 118 |
+
raise HTTPException(status_code=403, detail={"code": "feature_disabled", "message": "Rooms are disabled"})
|
| 119 |
+
user = await require_user_from_request(http_request)
|
| 120 |
+
user_id = str(user.get("id") or "")
|
| 121 |
+
store: RoomsStore = http_request.app.state.rooms_store
|
| 122 |
+
room = await store.get_room(room_id)
|
| 123 |
+
if not room:
|
| 124 |
+
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
| 125 |
+
if user_id not in room.members:
|
| 126 |
+
raise HTTPException(status_code=403, detail={"code": "not_member", "message": "Join the room first"})
|
| 127 |
+
members = await store.list_members(room_id=room_id)
|
| 128 |
+
return {"members": members or [], "myRole": room.roles.get(user_id, "member")}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@router.post("/api/rooms/{room_id}/kick")
|
| 132 |
+
async def room_kick(room_id: str, body: dict[str, Any], http_request: Request):
|
| 133 |
+
if not feature_enabled("rooms"):
|
| 134 |
+
raise HTTPException(status_code=403, detail={"code": "feature_disabled", "message": "Rooms are disabled"})
|
| 135 |
+
user = await require_user_from_request(http_request)
|
| 136 |
+
actor_id = str(user.get("id") or "")
|
| 137 |
+
target_id = str((body or {}).get("userId") or "").strip()
|
| 138 |
+
if not target_id:
|
| 139 |
+
raise HTTPException(status_code=400, detail={"code": "invalid_request", "message": "userId is required"})
|
| 140 |
+
store: RoomsStore = http_request.app.state.rooms_store
|
| 141 |
+
room = await store.get_room(room_id)
|
| 142 |
+
if not room:
|
| 143 |
+
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
| 144 |
+
if actor_id not in room.members:
|
| 145 |
+
raise HTTPException(status_code=403, detail={"code": "not_member", "message": "Join the room first"})
|
| 146 |
+
actor_role = (room.roles.get(actor_id) or "member").lower()
|
| 147 |
+
if actor_role not in {"owner", "moderator"}:
|
| 148 |
+
raise HTTPException(status_code=403, detail={"code": "forbidden", "message": "Insufficient privileges"})
|
| 149 |
+
if target_id == room.owner_user_id:
|
| 150 |
+
raise HTTPException(status_code=403, detail={"code": "forbidden", "message": "Cannot kick the owner"})
|
| 151 |
+
ok = await store.kick_member(room_id=room_id, user_id=target_id)
|
| 152 |
+
return {"ok": True, "kicked": ok}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@router.post("/api/rooms/{room_id}/ban")
|
| 156 |
+
async def room_ban(room_id: str, body: dict[str, Any], http_request: Request):
|
| 157 |
+
if not feature_enabled("rooms"):
|
| 158 |
+
raise HTTPException(status_code=403, detail={"code": "feature_disabled", "message": "Rooms are disabled"})
|
| 159 |
+
user = await require_user_from_request(http_request)
|
| 160 |
+
actor_id = str(user.get("id") or "")
|
| 161 |
+
target_id = str((body or {}).get("userId") or "").strip()
|
| 162 |
+
if not target_id:
|
| 163 |
+
raise HTTPException(status_code=400, detail={"code": "invalid_request", "message": "userId is required"})
|
| 164 |
+
store: RoomsStore = http_request.app.state.rooms_store
|
| 165 |
+
room = await store.get_room(room_id)
|
| 166 |
+
if not room:
|
| 167 |
+
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
| 168 |
+
if actor_id not in room.members:
|
| 169 |
+
raise HTTPException(status_code=403, detail={"code": "not_member", "message": "Join the room first"})
|
| 170 |
+
actor_role = (room.roles.get(actor_id) or "member").lower()
|
| 171 |
+
if actor_role not in {"owner", "moderator"}:
|
| 172 |
+
raise HTTPException(status_code=403, detail={"code": "forbidden", "message": "Insufficient privileges"})
|
| 173 |
+
if target_id == room.owner_user_id:
|
| 174 |
+
raise HTTPException(status_code=403, detail={"code": "forbidden", "message": "Cannot ban the owner"})
|
| 175 |
+
ok = await store.ban_member(room_id=room_id, user_id=target_id)
|
| 176 |
+
return {"ok": True, "banned": ok}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
@router.put("/api/rooms/{room_id}/roles")
|
| 180 |
+
async def room_set_role(room_id: str, body: dict[str, Any], http_request: Request):
|
| 181 |
+
if not feature_enabled("rooms"):
|
| 182 |
+
raise HTTPException(status_code=403, detail={"code": "feature_disabled", "message": "Rooms are disabled"})
|
| 183 |
+
user = await require_user_from_request(http_request)
|
| 184 |
+
actor_id = str(user.get("id") or "")
|
| 185 |
+
target_id = str((body or {}).get("userId") or "").strip()
|
| 186 |
+
role = str((body or {}).get("role") or "").strip().lower()
|
| 187 |
+
if not target_id or not role:
|
| 188 |
+
raise HTTPException(status_code=400, detail={"code": "invalid_request", "message": "userId and role are required"})
|
| 189 |
+
store: RoomsStore = http_request.app.state.rooms_store
|
| 190 |
+
room = await store.get_room(room_id)
|
| 191 |
+
if not room:
|
| 192 |
+
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Unknown roomId"})
|
| 193 |
+
if actor_id not in room.members:
|
| 194 |
+
raise HTTPException(status_code=403, detail={"code": "not_member", "message": "Join the room first"})
|
| 195 |
+
actor_role = (room.roles.get(actor_id) or "member").lower()
|
| 196 |
+
if actor_role != "owner":
|
| 197 |
+
raise HTTPException(status_code=403, detail={"code": "forbidden", "message": "Owner privileges required"})
|
| 198 |
+
ok = await store.set_role(room_id=room_id, user_id=target_id, role=role)
|
| 199 |
+
return {"ok": True, "updated": ok}
|
| 200 |
+
|
| 201 |
+
|
| 202 |
@router.get("/api/rooms/{room_id}/peers")
|
| 203 |
async def room_peers(room_id: str, http_request: Request):
|
| 204 |
if not feature_enabled("rooms"):
|
|
|
|
| 256 |
|
| 257 |
user_id = str(user.get("id") or "")
|
| 258 |
store: RoomsStore = websocket.app.state.rooms_store
|
| 259 |
+
room = await store.get_room(room_id)
|
| 260 |
+
if room and user_id in room.banned:
|
| 261 |
+
await websocket.send_text(_ws_json({"type": "error", "message": "banned"}))
|
| 262 |
+
await websocket.close()
|
| 263 |
+
return
|
| 264 |
room = await store.join_room(room_id=room_id, user_id=user_id)
|
| 265 |
if not room:
|
| 266 |
await websocket.send_text(_ws_json({"type": "error", "message": "unknown_room"}))
|
docs/TROUBLESHOOTING.md
CHANGED
|
@@ -75,3 +75,8 @@ Admins can also toggle feature overrides from Settings → Admin.
|
|
| 75 |
|
| 76 |
The Rooms view uses WebRTC DataChannels (optional, behind “Prefer P2P”). Some networks block UDP/WebRTC.
|
| 77 |
If P2P fails, keep “Prefer P2P” off and it will use server WebSockets for messaging.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
The Rooms view uses WebRTC DataChannels (optional, behind “Prefer P2P”). Some networks block UDP/WebRTC.
|
| 77 |
If P2P fails, keep “Prefer P2P” off and it will use server WebSockets for messaging.
|
| 78 |
+
|
| 79 |
+
## Password reset emails aren’t arriving
|
| 80 |
+
|
| 81 |
+
Supabase email delivery depends on your project auth settings and SMTP configuration.
|
| 82 |
+
Check Supabase → Authentication → Settings (and SMTP) and verify your site URL/redirect URLs include `/login`.
|
static/dashboard.html
CHANGED
|
@@ -884,13 +884,13 @@
|
|
| 884 |
<div id="rooms-list" class="flex-grow overflow-y-auto p-2 text-sm space-y-1"></div>
|
| 885 |
</div>
|
| 886 |
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
<label class="flex items-center gap-2 text-xs text-gray-300 bg-gray-700/60 px-2 py-1 rounded-lg">
|
| 895 |
<input id="rooms-prefer-p2p" type="checkbox" class="h-4 w-4 accent-blue-600">
|
| 896 |
Prefer P2P
|
|
@@ -899,12 +899,26 @@
|
|
| 899 |
class="bg-gray-700 hover:bg-gray-600 text-white px-2 py-1 rounded text-xs">Copy ID</button>
|
| 900 |
<button onclick="leaveActiveRoom()"
|
| 901 |
class="bg-red-600 hover:bg-red-700 text-white px-2 py-1 rounded text-xs">Leave</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
</div>
|
| 903 |
-
</div>
|
| 904 |
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
|
| 909 |
<div class="border-t border-gray-700 bg-gray-800 p-3">
|
| 910 |
<div class="flex items-end gap-2">
|
|
|
|
| 884 |
<div id="rooms-list" class="flex-grow overflow-y-auto p-2 text-sm space-y-1"></div>
|
| 885 |
</div>
|
| 886 |
|
| 887 |
+
<div class="flex-grow min-w-0 flex flex-col">
|
| 888 |
+
<div class="p-3 border-b border-gray-700 bg-gray-800 flex items-center justify-between gap-2">
|
| 889 |
+
<div class="min-w-0">
|
| 890 |
+
<div class="text-sm font-semibold text-gray-200 truncate" id="rooms-active-title">Select a room</div>
|
| 891 |
+
<div class="text-xs text-gray-400 truncate" id="rooms-active-subtitle">Create or join a room to start chatting.</div>
|
| 892 |
+
</div>
|
| 893 |
+
<div class="flex items-center gap-2 shrink-0">
|
| 894 |
<label class="flex items-center gap-2 text-xs text-gray-300 bg-gray-700/60 px-2 py-1 rounded-lg">
|
| 895 |
<input id="rooms-prefer-p2p" type="checkbox" class="h-4 w-4 accent-blue-600">
|
| 896 |
Prefer P2P
|
|
|
|
| 899 |
class="bg-gray-700 hover:bg-gray-600 text-white px-2 py-1 rounded text-xs">Copy ID</button>
|
| 900 |
<button onclick="leaveActiveRoom()"
|
| 901 |
class="bg-red-600 hover:bg-red-700 text-white px-2 py-1 rounded text-xs">Leave</button>
|
| 902 |
+
</div>
|
| 903 |
+
</div>
|
| 904 |
+
<div class="px-3 py-2 border-b border-gray-700 bg-gray-900/40 flex items-center justify-between gap-3">
|
| 905 |
+
<div class="text-xs text-gray-400">
|
| 906 |
+
<span class="font-semibold text-gray-200" id="rooms-my-role">role: —</span>
|
| 907 |
+
<span class="mx-2">•</span>
|
| 908 |
+
<button onclick="toggleRoomsMembers()" class="text-gray-300 hover:text-white underline underline-offset-2">members</button>
|
| 909 |
+
</div>
|
| 910 |
+
<div class="flex items-center gap-2">
|
| 911 |
+
<button onclick="loadRoomMembers()" class="bg-gray-700 hover:bg-gray-600 text-white px-2 py-1 rounded text-xs">Refresh</button>
|
| 912 |
+
</div>
|
| 913 |
+
</div>
|
| 914 |
+
<div id="rooms-members-panel" class="hidden border-b border-gray-700 bg-gray-900/30 p-3">
|
| 915 |
+
<div id="rooms-members" class="grid grid-cols-1 md:grid-cols-2 gap-2 text-xs"></div>
|
| 916 |
+
<div id="rooms-members-status" class="text-xs text-gray-500 mt-2"></div>
|
| 917 |
</div>
|
|
|
|
| 918 |
|
| 919 |
+
<div class="flex-grow min-h-0 overflow-y-auto p-4 space-y-3" id="rooms-messages">
|
| 920 |
+
<div class="text-sm text-gray-500">No room selected.</div>
|
| 921 |
+
</div>
|
| 922 |
|
| 923 |
<div class="border-t border-gray-700 bg-gray-800 p-3">
|
| 924 |
<div class="flex items-end gap-2">
|
static/dashboard.js
CHANGED
|
@@ -913,6 +913,7 @@ let supabase;
|
|
| 913 |
const { data: userData } = await supabase.auth.getUser();
|
| 914 |
const user = userData?.user;
|
| 915 |
if (user) {
|
|
|
|
| 916 |
const username =
|
| 917 |
user.user_metadata?.username ||
|
| 918 |
user.user_metadata?.name ||
|
|
@@ -3205,6 +3206,135 @@ let supabase;
|
|
| 3205 |
if (el) el.textContent = text || '';
|
| 3206 |
}
|
| 3207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3208 |
function renderRoomsMessagesEmpty(text) {
|
| 3209 |
const box = document.getElementById('rooms-messages');
|
| 3210 |
if (!box) return;
|
|
@@ -3390,8 +3520,11 @@ let supabase;
|
|
| 3390 |
roomsMessageEls = new Map();
|
| 3391 |
updateRoomsHeader(roomsActiveRoomId, name || 'Room');
|
| 3392 |
renderRoomsMessagesEmpty('Loading…');
|
|
|
|
|
|
|
| 3393 |
await loadRoomsList();
|
| 3394 |
await loadRoomHistory();
|
|
|
|
| 3395 |
await connectRoomsWs();
|
| 3396 |
}
|
| 3397 |
|
|
|
|
| 913 |
const { data: userData } = await supabase.auth.getUser();
|
| 914 |
const user = userData?.user;
|
| 915 |
if (user) {
|
| 916 |
+
window.__sbUserId = (user.id || '').trim();
|
| 917 |
const username =
|
| 918 |
user.user_metadata?.username ||
|
| 919 |
user.user_metadata?.name ||
|
|
|
|
| 3206 |
if (el) el.textContent = text || '';
|
| 3207 |
}
|
| 3208 |
|
| 3209 |
+
function setRoomsMembersStatus(text) {
|
| 3210 |
+
const el = document.getElementById('rooms-members-status');
|
| 3211 |
+
if (el) el.textContent = text || '';
|
| 3212 |
+
}
|
| 3213 |
+
|
| 3214 |
+
function setRoomsMyRole(role) {
|
| 3215 |
+
const el = document.getElementById('rooms-my-role');
|
| 3216 |
+
if (!el) return;
|
| 3217 |
+
el.textContent = `role: ${role || '—'}`;
|
| 3218 |
+
}
|
| 3219 |
+
|
| 3220 |
+
function toggleRoomsMembers(forceOpen = null) {
|
| 3221 |
+
const panel = document.getElementById('rooms-members-panel');
|
| 3222 |
+
if (!panel) return;
|
| 3223 |
+
const open = forceOpen == null ? panel.classList.contains('hidden') : !!forceOpen;
|
| 3224 |
+
panel.classList.toggle('hidden', !open);
|
| 3225 |
+
}
|
| 3226 |
+
|
| 3227 |
+
function renderRoomMembers(data) {
|
| 3228 |
+
const el = document.getElementById('rooms-members');
|
| 3229 |
+
if (!el) return;
|
| 3230 |
+
el.innerHTML = '';
|
| 3231 |
+
const members = Array.isArray(data?.members) ? data.members : [];
|
| 3232 |
+
const myRole = String(data?.myRole || '').trim();
|
| 3233 |
+
setRoomsMyRole(myRole || 'member');
|
| 3234 |
+
|
| 3235 |
+
if (!members.length) {
|
| 3236 |
+
const empty = document.createElement('div');
|
| 3237 |
+
empty.className = 'text-gray-500';
|
| 3238 |
+
empty.textContent = 'No members.';
|
| 3239 |
+
el.appendChild(empty);
|
| 3240 |
+
return;
|
| 3241 |
+
}
|
| 3242 |
+
for (const m of members) {
|
| 3243 |
+
const uid = String(m?.userId || '').trim();
|
| 3244 |
+
const role = String(m?.role || 'member').trim();
|
| 3245 |
+
if (!uid) continue;
|
| 3246 |
+
|
| 3247 |
+
const card = document.createElement('div');
|
| 3248 |
+
card.className = 'bg-gray-800/40 border border-gray-700 rounded-lg px-3 py-2 flex items-center justify-between gap-2';
|
| 3249 |
+
|
| 3250 |
+
const left = document.createElement('div');
|
| 3251 |
+
left.className = 'min-w-0';
|
| 3252 |
+
const a = document.createElement('div');
|
| 3253 |
+
a.className = 'text-gray-100 font-semibold truncate';
|
| 3254 |
+
a.textContent = uid.slice(0, 12);
|
| 3255 |
+
const b = document.createElement('div');
|
| 3256 |
+
b.className = 'text-gray-400 truncate';
|
| 3257 |
+
b.textContent = role;
|
| 3258 |
+
left.appendChild(a);
|
| 3259 |
+
left.appendChild(b);
|
| 3260 |
+
|
| 3261 |
+
const actions = document.createElement('div');
|
| 3262 |
+
actions.className = 'flex items-center gap-2 shrink-0';
|
| 3263 |
+
|
| 3264 |
+
const canModerate = myRole === 'owner' || myRole === 'moderator';
|
| 3265 |
+
const selfUserId = (window.__sbUserId || '').trim();
|
| 3266 |
+
const isSelf = selfUserId && uid === selfUserId;
|
| 3267 |
+
const isOwner = role === 'owner';
|
| 3268 |
+
if (canModerate && !isSelf && !isOwner) {
|
| 3269 |
+
const kick = document.createElement('button');
|
| 3270 |
+
kick.className = 'bg-gray-700 hover:bg-gray-600 text-white px-2 py-1 rounded text-xs';
|
| 3271 |
+
kick.textContent = 'Kick';
|
| 3272 |
+
kick.onclick = () => kickRoomMember(uid);
|
| 3273 |
+
|
| 3274 |
+
const ban = document.createElement('button');
|
| 3275 |
+
ban.className = 'bg-red-700 hover:bg-red-600 text-white px-2 py-1 rounded text-xs';
|
| 3276 |
+
ban.textContent = 'Ban';
|
| 3277 |
+
ban.onclick = () => banRoomMember(uid);
|
| 3278 |
+
|
| 3279 |
+
actions.appendChild(kick);
|
| 3280 |
+
actions.appendChild(ban);
|
| 3281 |
+
}
|
| 3282 |
+
|
| 3283 |
+
card.appendChild(left);
|
| 3284 |
+
card.appendChild(actions);
|
| 3285 |
+
el.appendChild(card);
|
| 3286 |
+
}
|
| 3287 |
+
}
|
| 3288 |
+
|
| 3289 |
+
async function loadRoomMembers() {
|
| 3290 |
+
const rid = roomsActiveRoomId;
|
| 3291 |
+
if (!rid) return;
|
| 3292 |
+
try {
|
| 3293 |
+
setRoomsMembersStatus('Loading…');
|
| 3294 |
+
const res = await authFetch(`/api/rooms/${encodeURIComponent(rid)}/members`);
|
| 3295 |
+
if (!res.ok) throw new Error(await res.text());
|
| 3296 |
+
const data = await res.json();
|
| 3297 |
+
renderRoomMembers(data);
|
| 3298 |
+
setRoomsMembersStatus('');
|
| 3299 |
+
} catch (e) {
|
| 3300 |
+
setRoomsMembersStatus(`Failed: ${e?.message || e}`);
|
| 3301 |
+
}
|
| 3302 |
+
}
|
| 3303 |
+
|
| 3304 |
+
async function kickRoomMember(userId) {
|
| 3305 |
+
const rid = roomsActiveRoomId;
|
| 3306 |
+
if (!rid) return;
|
| 3307 |
+
if (!confirm(`Kick ${String(userId).slice(0, 12)}?`)) return;
|
| 3308 |
+
try {
|
| 3309 |
+
const res = await authFetch(`/api/rooms/${encodeURIComponent(rid)}/kick`, {
|
| 3310 |
+
method: 'POST',
|
| 3311 |
+
headers: { 'Content-Type': 'application/json' },
|
| 3312 |
+
body: JSON.stringify({ userId }),
|
| 3313 |
+
});
|
| 3314 |
+
if (!res.ok) throw new Error(await res.text());
|
| 3315 |
+
await loadRoomMembers();
|
| 3316 |
+
} catch (e) {
|
| 3317 |
+
alert(`Kick failed: ${e?.message || e}`);
|
| 3318 |
+
}
|
| 3319 |
+
}
|
| 3320 |
+
|
| 3321 |
+
async function banRoomMember(userId) {
|
| 3322 |
+
const rid = roomsActiveRoomId;
|
| 3323 |
+
if (!rid) return;
|
| 3324 |
+
if (!confirm(`Ban ${String(userId).slice(0, 12)}?`)) return;
|
| 3325 |
+
try {
|
| 3326 |
+
const res = await authFetch(`/api/rooms/${encodeURIComponent(rid)}/ban`, {
|
| 3327 |
+
method: 'POST',
|
| 3328 |
+
headers: { 'Content-Type': 'application/json' },
|
| 3329 |
+
body: JSON.stringify({ userId }),
|
| 3330 |
+
});
|
| 3331 |
+
if (!res.ok) throw new Error(await res.text());
|
| 3332 |
+
await loadRoomMembers();
|
| 3333 |
+
} catch (e) {
|
| 3334 |
+
alert(`Ban failed: ${e?.message || e}`);
|
| 3335 |
+
}
|
| 3336 |
+
}
|
| 3337 |
+
|
| 3338 |
function renderRoomsMessagesEmpty(text) {
|
| 3339 |
const box = document.getElementById('rooms-messages');
|
| 3340 |
if (!box) return;
|
|
|
|
| 3520 |
roomsMessageEls = new Map();
|
| 3521 |
updateRoomsHeader(roomsActiveRoomId, name || 'Room');
|
| 3522 |
renderRoomsMessagesEmpty('Loading…');
|
| 3523 |
+
setRoomsMyRole('');
|
| 3524 |
+
toggleRoomsMembers(false);
|
| 3525 |
await loadRoomsList();
|
| 3526 |
await loadRoomHistory();
|
| 3527 |
+
await loadRoomMembers();
|
| 3528 |
await connectRoomsWs();
|
| 3529 |
}
|
| 3530 |
|
static/index.html
CHANGED
|
@@ -30,6 +30,11 @@
|
|
| 30 |
required>
|
| 31 |
</div>
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
<div class="flex space-x-4">
|
| 34 |
<button type="submit" id="login-btn"
|
| 35 |
class="w-full px-5 py-2.5 text-sm font-medium bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 focus:ring-blue-800">Login</button>
|
|
@@ -37,6 +42,47 @@
|
|
| 37 |
class="w-full px-5 py-2.5 text-sm font-medium bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-800">Register</button>
|
| 38 |
</div>
|
| 39 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
</div>
|
| 41 |
<script src="/static/login.js"></script>
|
| 42 |
</body>
|
|
|
|
| 30 |
required>
|
| 31 |
</div>
|
| 32 |
|
| 33 |
+
<div class="flex items-center justify-between text-sm">
|
| 34 |
+
<button type="button" id="forgot-btn"
|
| 35 |
+
class="text-gray-300 hover:text-white underline underline-offset-2">Forgot password?</button>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
<div class="flex space-x-4">
|
| 39 |
<button type="submit" id="login-btn"
|
| 40 |
class="w-full px-5 py-2.5 text-sm font-medium bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 focus:ring-blue-800">Login</button>
|
|
|
|
| 42 |
class="w-full px-5 py-2.5 text-sm font-medium bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-800">Register</button>
|
| 43 |
</div>
|
| 44 |
</form>
|
| 45 |
+
|
| 46 |
+
<div id="reset-panel" class="hidden space-y-4">
|
| 47 |
+
<div class="text-sm text-gray-300">
|
| 48 |
+
<div class="font-semibold text-gray-100">Reset password</div>
|
| 49 |
+
<div class="text-gray-400">Enter your email to receive a reset link.</div>
|
| 50 |
+
</div>
|
| 51 |
+
<div>
|
| 52 |
+
<label for="reset-email" class="block mb-2 text-sm font-medium">Email</label>
|
| 53 |
+
<input type="email" id="reset-email"
|
| 54 |
+
class="w-full p-2.5 bg-gray-700 border border-gray-600 rounded-lg focus:ring-blue-500 focus:border-blue-500">
|
| 55 |
+
</div>
|
| 56 |
+
<div class="flex gap-2">
|
| 57 |
+
<button type="button" id="send-reset-btn"
|
| 58 |
+
class="flex-1 px-5 py-2.5 text-sm font-medium bg-indigo-600 rounded-lg hover:bg-indigo-700 focus:ring-4 focus:ring-indigo-800">Send link</button>
|
| 59 |
+
<button type="button" id="cancel-reset-btn"
|
| 60 |
+
class="px-5 py-2.5 text-sm font-medium bg-gray-700 rounded-lg hover:bg-gray-600">Cancel</button>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<div id="update-panel" class="hidden space-y-4">
|
| 65 |
+
<div class="text-sm text-gray-300">
|
| 66 |
+
<div class="font-semibold text-gray-100">Set a new password</div>
|
| 67 |
+
<div class="text-gray-400">You opened a password recovery link. Choose a new password.</div>
|
| 68 |
+
</div>
|
| 69 |
+
<div>
|
| 70 |
+
<label for="new-password" class="block mb-2 text-sm font-medium">New password</label>
|
| 71 |
+
<input type="password" id="new-password"
|
| 72 |
+
class="w-full p-2.5 bg-gray-700 border border-gray-600 rounded-lg focus:ring-blue-500 focus:border-blue-500">
|
| 73 |
+
</div>
|
| 74 |
+
<div>
|
| 75 |
+
<label for="confirm-password" class="block mb-2 text-sm font-medium">Confirm password</label>
|
| 76 |
+
<input type="password" id="confirm-password"
|
| 77 |
+
class="w-full p-2.5 bg-gray-700 border border-gray-600 rounded-lg focus:ring-blue-500 focus:border-blue-500">
|
| 78 |
+
</div>
|
| 79 |
+
<div class="flex gap-2">
|
| 80 |
+
<button type="button" id="update-password-btn"
|
| 81 |
+
class="flex-1 px-5 py-2.5 text-sm font-medium bg-green-600 rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-800">Update password</button>
|
| 82 |
+
<button type="button" id="cancel-update-btn"
|
| 83 |
+
class="px-5 py-2.5 text-sm font-medium bg-gray-700 rounded-lg hover:bg-gray-600">Cancel</button>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
</div>
|
| 87 |
<script src="/static/login.js"></script>
|
| 88 |
</body>
|
static/login.js
CHANGED
|
@@ -16,10 +16,27 @@ let supabase;
|
|
| 16 |
registerBtn.style.display = 'none';
|
| 17 |
}
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
const { data: { session } } = await supabase.auth.getSession();
|
| 21 |
-
if (session) {
|
| 22 |
window.location.href = '/app';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
} catch (error) {
|
| 25 |
console.error('Error initializing Supabase:', error);
|
|
@@ -27,6 +44,45 @@ let supabase;
|
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
function showAlert(message, type = 'error') {
|
| 31 |
const alert = document.getElementById('alert');
|
| 32 |
alert.textContent = message;
|
|
@@ -79,6 +135,58 @@ let supabase;
|
|
| 79 |
handleAuth('login');
|
| 80 |
});
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
document.getElementById('register-btn').addEventListener('click', () => {
|
| 83 |
if (localStorage.getItem('auth_allow_signup_v1') === '1') {
|
| 84 |
handleAuth('register');
|
|
|
|
| 16 |
registerBtn.style.display = 'none';
|
| 17 |
}
|
| 18 |
|
| 19 |
+
supabase.auth.onAuthStateChange((event, session) => {
|
| 20 |
+
if (event === 'PASSWORD_RECOVERY') {
|
| 21 |
+
showUpdatePanel();
|
| 22 |
+
return;
|
| 23 |
+
}
|
| 24 |
+
const recovery = isRecoveryUrl();
|
| 25 |
+
if (session && !recovery) {
|
| 26 |
+
window.location.href = '/app';
|
| 27 |
+
}
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
const recovery = isRecoveryUrl();
|
| 31 |
const { data: { session } } = await supabase.auth.getSession();
|
| 32 |
+
if (session && !recovery) {
|
| 33 |
window.location.href = '/app';
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
if (recovery) {
|
| 37 |
+
showUpdatePanel();
|
| 38 |
+
} else {
|
| 39 |
+
showLoginPanel();
|
| 40 |
}
|
| 41 |
} catch (error) {
|
| 42 |
console.error('Error initializing Supabase:', error);
|
|
|
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
+
function isRecoveryUrl() {
|
| 48 |
+
const hash = String(window.location.hash || '');
|
| 49 |
+
const search = String(window.location.search || '');
|
| 50 |
+
return hash.includes('type=recovery') || search.includes('type=recovery') || hash.includes('recovery');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function getPanels() {
|
| 54 |
+
return {
|
| 55 |
+
login: document.getElementById('auth-form'),
|
| 56 |
+
reset: document.getElementById('reset-panel'),
|
| 57 |
+
update: document.getElementById('update-panel'),
|
| 58 |
+
};
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function showLoginPanel() {
|
| 62 |
+
const { login, reset, update } = getPanels();
|
| 63 |
+
if (login) login.classList.remove('hidden');
|
| 64 |
+
if (reset) reset.classList.add('hidden');
|
| 65 |
+
if (update) update.classList.add('hidden');
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function showResetPanel() {
|
| 69 |
+
const { login, reset, update } = getPanels();
|
| 70 |
+
if (login) login.classList.add('hidden');
|
| 71 |
+
if (reset) reset.classList.remove('hidden');
|
| 72 |
+
if (update) update.classList.add('hidden');
|
| 73 |
+
|
| 74 |
+
const email = document.getElementById('email')?.value || '';
|
| 75 |
+
const el = document.getElementById('reset-email');
|
| 76 |
+
if (el && email) el.value = email;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function showUpdatePanel() {
|
| 80 |
+
const { login, reset, update } = getPanels();
|
| 81 |
+
if (login) login.classList.add('hidden');
|
| 82 |
+
if (reset) reset.classList.add('hidden');
|
| 83 |
+
if (update) update.classList.remove('hidden');
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
function showAlert(message, type = 'error') {
|
| 87 |
const alert = document.getElementById('alert');
|
| 88 |
alert.textContent = message;
|
|
|
|
| 135 |
handleAuth('login');
|
| 136 |
});
|
| 137 |
|
| 138 |
+
document.getElementById('forgot-btn').addEventListener('click', () => {
|
| 139 |
+
showResetPanel();
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
document.getElementById('cancel-reset-btn').addEventListener('click', () => {
|
| 143 |
+
showLoginPanel();
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
document.getElementById('send-reset-btn').addEventListener('click', async () => {
|
| 147 |
+
const email = (document.getElementById('reset-email')?.value || '').trim();
|
| 148 |
+
if (!email) {
|
| 149 |
+
showAlert('Enter your email to receive a reset link.');
|
| 150 |
+
return;
|
| 151 |
+
}
|
| 152 |
+
try {
|
| 153 |
+
const redirectTo = `${window.location.origin}/login`;
|
| 154 |
+
const { error } = await supabase.auth.resetPasswordForEmail(email, { redirectTo });
|
| 155 |
+
if (error) throw error;
|
| 156 |
+
showAlert('Reset link sent. Check your email.', 'success');
|
| 157 |
+
showLoginPanel();
|
| 158 |
+
} catch (e) {
|
| 159 |
+
showAlert(e?.message || String(e));
|
| 160 |
+
}
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
document.getElementById('cancel-update-btn').addEventListener('click', async () => {
|
| 164 |
+
try { await supabase.auth.signOut(); } catch { }
|
| 165 |
+
window.location.replace('/login');
|
| 166 |
+
});
|
| 167 |
+
|
| 168 |
+
document.getElementById('update-password-btn').addEventListener('click', async () => {
|
| 169 |
+
const p1 = (document.getElementById('new-password')?.value || '').trim();
|
| 170 |
+
const p2 = (document.getElementById('confirm-password')?.value || '').trim();
|
| 171 |
+
if (!p1 || p1.length < 8) {
|
| 172 |
+
showAlert('Password must be at least 8 characters.');
|
| 173 |
+
return;
|
| 174 |
+
}
|
| 175 |
+
if (p1 !== p2) {
|
| 176 |
+
showAlert('Passwords do not match.');
|
| 177 |
+
return;
|
| 178 |
+
}
|
| 179 |
+
try {
|
| 180 |
+
const { error } = await supabase.auth.updateUser({ password: p1 });
|
| 181 |
+
if (error) throw error;
|
| 182 |
+
showAlert('Password updated. You can log in now.', 'success');
|
| 183 |
+
try { await supabase.auth.signOut(); } catch { }
|
| 184 |
+
window.location.replace('/login');
|
| 185 |
+
} catch (e) {
|
| 186 |
+
showAlert(e?.message || String(e));
|
| 187 |
+
}
|
| 188 |
+
});
|
| 189 |
+
|
| 190 |
document.getElementById('register-btn').addEventListener('click', () => {
|
| 191 |
if (localStorage.getItem('auth_allow_signup_v1') === '1') {
|
| 192 |
handleAuth('register');
|
tests/test_security_gates.py
CHANGED
|
@@ -51,6 +51,11 @@ def test_rooms_ws_requires_token(client: TestClient):
|
|
| 51 |
assert "missing_token" in msg or msg == ""
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def test_features_can_be_disabled(monkeypatch: pytest.MonkeyPatch):
|
| 55 |
monkeypatch.setenv("SUPABASE_URL", "https://example.supabase.co")
|
| 56 |
monkeypatch.setenv("SUPABASE_KEY", "dummy")
|
|
|
|
| 51 |
assert "missing_token" in msg or msg == ""
|
| 52 |
|
| 53 |
|
| 54 |
+
def test_room_members_requires_auth(client: TestClient):
|
| 55 |
+
res = client.get("/api/rooms/x/members")
|
| 56 |
+
assert res.status_code == 401
|
| 57 |
+
|
| 58 |
+
|
| 59 |
def test_features_can_be_disabled(monkeypatch: pytest.MonkeyPatch):
|
| 60 |
monkeypatch.setenv("SUPABASE_URL", "https://example.supabase.co")
|
| 61 |
monkeypatch.setenv("SUPABASE_KEY", "dummy")
|