Files
LoveACE-EndF/provider/aufe/jwc/depends.py
2025-08-03 16:50:56 +08:00

37 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import Depends, HTTPException
from provider.loveac.authme import fetch_user_by_token
from provider.aufe.jwc import JWCClient
from provider.aufe.client import AUFEConnection
from database.user import User
async def get_jwc_client(
user: User = Depends(fetch_user_by_token),
) -> JWCClient:
"""
获取教务处客户端
:param authme_request: AuthmeRequest
:return: JWCClient
"""
if not user:
raise HTTPException(status_code=400, detail="无效的令牌或用户不存在")
aufe = AUFEConnection.create_or_get_connection("vpn.aufe.edu.cn", user.userid)
if not aufe.login_status():
userid = user.userid
easyconnect_password = user.easyconnect_password
if not await aufe.login(userid, easyconnect_password):
raise HTTPException(
status_code=400,
detail="VPN登录失败请检查用户名和密码",
)
if not aufe.uaap_login_status():
userid = user.userid
password = user.password
if not await aufe.uaap_login(userid, password):
raise HTTPException(
status_code=400,
detail="大学登录失败,请检查用户名和密码",
)
return JWCClient(aufe)