예제 #1
0
 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('服务器走丢啦~')
예제 #2
0
 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'))
예제 #3
0
    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)
예제 #4
0
파일: auth.py 프로젝트: Mivinci/cqupt-piper
 def update_user(cls, message: str = '要更改绑定吗?'):
     if input(f'{message} [y/N]: ') != 'N':
         cls.enter_user()
         Log.fatal('更改成功')
     else:
         Log.fatal('运行命令 cqupt --auth 可以更改密码哦~')
예제 #5
0
 def drop(self):
     Auth.drop_config()
     Log.fatal('已删除配置')
예제 #6
0
 def clear(self):
     Auth.clear_cookie()
     Log.fatal('已清除缓存')
예제 #7
0
 def target_wrapper(*args, **kwargs):
     try:
         target(*args, **kwargs)
     except KeyboardInterrupt:
         Log.fatal('Bye!', prog='')