Files
NJUPT-Suan-API/njupt_api/zhengfang/sso.py
MangoFanFanw 16bd8e9f9a jwxt()
1. 将 jwxt() 移动到 njupt_api 下,实现根据设置选择教务系统登录方式。
2. 将 api_router.py 和 mcp_router.py 中的对 ZhengFang() 的调用全部替换为对 jwxt() 的调用。
2026-04-21 17:42:59 +08:00

44 lines
1.5 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 njupt_api.baselib import PlayContextManager, logger
from .exc import LoginError
class SSO(PlayContextManager):
def __init__(self) -> None:
super().__init__()
async def login(self, username: str, password: str) -> bool:
"""使用用户名和密码实现登录南邮统一身份验证。
Parameters:
username: 用户名,学号,一般为一位大写字母+八位数字
password: 密码
Returns:
bool表明判登录是否成功。
Raises:
LoginError: 登录失败,暂时不包含任何提示信息……
"""
await self.page.goto("http://i.njupt.edu.cn/")
await self.page.fill('input[name="username"]', username)
await self.page.fill('input[type="password"]', password)
await self.page.click('button[type="button"]')
await self.page.wait_for_load_state("networkidle")
if "user-login" in self.page.url:
logger.error(f"{username} | 登录失败,请检查学号和密码是否正确。")
raise LoginError("unknown")
logger.info(f"{username} | 登录南邮统一身份认证成功。")
self.isLogin = True
return True
async def goto_zf(self) -> None:
sub_frame = self.page.frame_locator('iframe[name="iframe0"]')
async with self.context.expect_event("page") as new_page_event:
await sub_frame.locator('a[title="教务系统"]').click()
self.page = await new_page_event.value
return