feat(P1): 多租户账号体系——User表+security(pbkdf2 Hydro兼容)+HydroAdmin mongodb直连建号(复刻UserModel.create,fluent-前缀)+session池+JWT+auth API(register/login/logout/me/status)+login/register页+index守卫+判题按用户会话隔离
这个提交包含在:
@@ -39,20 +39,35 @@ class HydroAdapter(BaseJudgeEngine):
|
||||
self.password = password
|
||||
self.use_lecture_api = use_lecture_api
|
||||
self._client: httpx.AsyncClient | None = None
|
||||
self._user_sid: str | None = None # 多租户:用户会话 cookie(判题挂用户名下)
|
||||
|
||||
def set_user_sid(self, sid: str) -> None:
|
||||
"""注入用户 _sid 会话(多租户判题:记录挂该用户 Hydro 账号名下)。"""
|
||||
self._user_sid = sid
|
||||
self._client = None
|
||||
|
||||
async def _login(self) -> httpx.AsyncClient:
|
||||
if self._client is not None:
|
||||
return self._client
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
|
||||
"Accept": "text/html,application/json,*/*",
|
||||
}
|
||||
# 多租户优先:直接用用户会话 cookie
|
||||
if self._user_sid:
|
||||
self._client = httpx.AsyncClient(
|
||||
base_url=self.base_url, timeout=30, follow_redirects=True,
|
||||
headers=headers, cookies={"_sid": self._user_sid},
|
||||
)
|
||||
logger.info("Hydro 判题使用用户会话: %s", self.base_url)
|
||||
return self._client
|
||||
if not self.username or not self.password:
|
||||
raise JudgeError("HydroOJ 服务账号未配置(HYDRO_USER / HYDRO_PASS)")
|
||||
client = httpx.AsyncClient(
|
||||
base_url=self.base_url,
|
||||
timeout=30,
|
||||
follow_redirects=True,
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
|
||||
"Accept": "text/html,application/json,*/*",
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
# 1. 取登录页 csrf
|
||||
r = await client.get("/login")
|
||||
|
||||
在新工单中引用
屏蔽一个用户