コード例 #1
0
 def test_auth_fail(self):
     login = Login("5120170000", "000000")
     res, info = login.try_login()
     print(res)
     assert res is False
     print(info)
     assert info == "AuthFail"
コード例 #2
0
 def test_auth_success(self):
     u = _("testusername")
     p = _("testpassword")
     if not (u and p):
         pytest.skip(
             msg="requires testusername and testpassword to test success")
     login = Login(u, p)
     res, info = login.try_login()
     print(res)
     assert res is True
コード例 #3
0
ファイル: user.py プロジェクト: KelabDev/iswust_bot
async def bind():
    res = await request.get_json()
    qq = res.get("qq")
    username = res.get("username")
    password = res.get("password")
    token = res.get("token")

    logger.debug("username:{} password:{} token:{}".format(
        username, password, token))

    result, msg = check_args(qq=qq,
                             username=username,
                             password=password,
                             token=token)

    if to_token(qq) != token:
        abort(403)

    if not result:
        return false_ret(msg=msg)

    logger.info("qq{}正在请求绑定!".format(qq))
    # 是否已经绑定
    user = await User.get(str(qq))

    _bot = get_bot()
    if user is None:
        logger.info("qq{}是新用户,正在尝试登录教务处...".format(qq))
        u = Login(username, password)
        is_log, log_resp = await run_sync_func(u.try_login)
        if is_log:
            user_info = await run_sync_func(log_resp.json)
            logger.debug(user_info)
            await logger.complete()

            await User.add(
                qq=qq,
                student_id=username,
                password=password,
                cookies=pickle.dumps(u.get_cookies()),
            )
            logger.info("qq{}绑定成功!".format(qq))
            await _bot.send(qq2event(qq), "教务处绑定成功!")
            await _bot.send(qq2event(qq), "可以向我发送 帮助 来继续使用~")
            await _bot.send(qq2event(qq), "点击 https://bot.artin.li 来查看帮助~")
            await _bot.send(qq2event(qq),
                            f"点击个人中心可以配置更多: {get_user_center(qq2event(qq))}")
            return true_ret("qq绑定成功!")
        else:
            logger.info("qq{}绑定失败!".format(qq))
            await _bot.send(qq2event(qq), "教务处绑定失败!")
            return false_ret("qq绑定失败!失败原因是{}".format(log_resp))
    return false_ret("该qq已经绑定了!")
コード例 #4
0
    async def get_cookies(cls, user: "******"):
        from auth_swust import Login
        from auth_swust import request as login_request

        cookies = pickle.loads(user.cookies)
        sess = login_request.Session(cookies)
        res = await run_sync_func(
            sess.get, API.jwc_index, allow_redirects=False, verify=False
        )

        # 302重定向了,session 失效,重新获取session
        if res.status_code == 302 or res.status_code == 301:
            u_ = Login(user.student_id, user.password)
            is_log, _ = await run_sync_func(u_.try_login)
            if is_log:
                cookies = pickle.dumps(u_.get_cookies())
                await user.update(cookies=cookies).apply()
                logger.info(f"更新qq: {user.qq} 的 session")
                return u_.get_cookies()
        else:
            return cookies
コード例 #5
0
ファイル: run.py プロジェクト: KelabDev/course2ics
load_dotenv()
environ["no_proxy"] = "*"

from auth_swust import Login
from loguru import logger

from src.gen_ics import generate_class_schedule
from src.parse_api import get_course_api


# 登录部分
username = _("c2i_username")
password = _("c2i_password")
path = _("c2i_path", "./")

if not username or not password:
    raise ValueError("未设置用户名密码")

username_li = username.split(",")
password_li = password.split(",")

for u, p in zip(username_li, password_li):
    login = Login(u, p)
    res, _ = login.try_login()
    if res:
        sess = login.sess
        api = get_course_api(sess)
        generate_class_schedule(api, u, path)
    else:
        logger.error(f"{u} 生成日历出错!")