Spaces:
Runtime error
Runtime error
Download routers/admin_auth.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 666 Bytes
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/routers/admin_auth.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/routers/admin_auth.py
-
curl -L -o admin_auth.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/routers/admin_auth.py
666 Bytes
| # routers/admin_auth.py | |
| from fastapi import APIRouter, HTTPException, Form | |
| import jwt | |
| from datetime import datetime, timedelta | |
| from core.config import settings | |
| router = APIRouter() | |
| # IMPORTANT: Do NOT use /admin/login (reserved by starlette-admin) | |
| def admin_login(password: str = Form(...)): | |
| if password != settings.ADMIN_SECRET: | |
| raise HTTPException(status_code=401, detail="Invalid password") | |
| token = jwt.encode( | |
| { | |
| "role": "admin", | |
| "exp": datetime.utcnow() + timedelta(days=1) | |
| }, | |
| settings.ADMIN_SECRET, | |
| algorithm="HS256" | |
| ) | |
| return {"token": token} | |