Spaces:
Sleeping
Sleeping
add new user
Browse files
README.md
CHANGED
|
@@ -53,3 +53,13 @@ Request body:
|
|
| 53 |
Notes:
|
| 54 |
|
| 55 |
- Users created via `/register` are stored in-memory (no persistence across restarts).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
Notes:
|
| 54 |
|
| 55 |
- Users created via `/register` are stored in-memory (no persistence across restarts).
|
| 56 |
+
|
| 57 |
+
### Current user info
|
| 58 |
+
|
| 59 |
+
`GET /me` (JWT required) returns the current username and whether the user is an admin:
|
| 60 |
+
|
| 61 |
+
```json
|
| 62 |
+
{ "ok": true, "username": "alice", "is_admin": true }
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
- Used by the frontend to show the “Register User” panel only for admins.
|
app.py
CHANGED
|
@@ -173,6 +173,25 @@ def register():
|
|
| 173 |
return jsonify({"ok": True, "username": username}), 200
|
| 174 |
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
# ============================================================
|
| 177 |
# NON-STREAMING CHAT (JSON → JSON)
|
| 178 |
# ============================================================
|
|
|
|
| 173 |
return jsonify({"ok": True, "username": username}), 200
|
| 174 |
|
| 175 |
|
| 176 |
+
# ============================================================
|
| 177 |
+
# CURRENT USER INFO (JWT REQUIRED)
|
| 178 |
+
# ============================================================
|
| 179 |
+
@app.get("/me")
|
| 180 |
+
@jwt_required()
|
| 181 |
+
def me():
|
| 182 |
+
identity = (get_jwt_identity() or "").strip()
|
| 183 |
+
return (
|
| 184 |
+
jsonify(
|
| 185 |
+
{
|
| 186 |
+
"ok": True,
|
| 187 |
+
"username": identity,
|
| 188 |
+
"is_admin": bool(identity and identity in ADMIN_USERS),
|
| 189 |
+
}
|
| 190 |
+
),
|
| 191 |
+
200,
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
# ============================================================
|
| 196 |
# NON-STREAMING CHAT (JSON → JSON)
|
| 197 |
# ============================================================
|