def login(user: dict, cookie: dict) -> dict: user.update(cookie) try: return loads(post(URL_LOGIN_API, data=user).text) except ConnectionError: Loading.done = True Auth.clear_cookie() Log.fatal('服务器走丢啦~')
def handle_login(resp: dict): if resp.get('code') == 401: print('\n' + resp.get('msg')) Auth.update_user() Auth.clear_cookie() elif resp.get('code') == 200: print('\n\033[92m登录成功\033[0m') else: Auth.clear_cookie() Log.fatal(resp.get('msg'))
def authorize(self): if not self.user: self.user = Auth.add_user() if self.cookie is None: try: self.session.get(URL_LOGIN) except ConnectionError: Log.fatal('网络走丢啦~') self.cookie = self.session.cookies.get_dict() # print(self.cookie) Auth.save_cookie(self.cookie) Request.handle_login(Request.login(self.user, self.cookie)) else: self.session.cookies.update(self.cookie)
def update_user(cls, message: str = '要更改绑定吗?'): if input(f'{message} [y/N]: ') != 'N': cls.enter_user() Log.fatal('更改成功') else: Log.fatal('运行命令 cqupt --auth 可以更改密码哦~')
def drop(self): Auth.drop_config() Log.fatal('已删除配置')
def clear(self): Auth.clear_cookie() Log.fatal('已清除缓存')
def target_wrapper(*args, **kwargs): try: target(*args, **kwargs) except KeyboardInterrupt: Log.fatal('Bye!', prog='')