Beispiel #1
0
def input_name_pass_login(ojOperate):
    username = input(termcolor.colored('请输入用户名: ', 'cyan'))
    password = getpass.getpass(termcolor.colored('请输入密码: ', 'cyan'))
    loginSuccess = ojOperate.login(username, password)

    if loginSuccess:
        # 保存cookie
        RequestUtil.session.cookies.save(ignore_discard=True,
                                         ignore_expires=True)
        PrintUtil.info('登录成功!')
        # 保存账号密码
        option = input(termcolor.colored(u'\n是否保存用户名及密码? (yes/no) ', 'cyan'))
        if option == 'yes':
            # 保存密码
            try:
                globalVar.BASE_CONF.set('user', 'username', username)
                # 先简单base64编码加密意思意思...
                bytesString = password.encode(encoding="utf-8")
                encodestr = base64.b64encode(bytesString)
                globalVar.BASE_CONF.set('user', 'password',
                                        encodestr.decode(encoding='utf-8'))
                with open(globalVar.BASE_CONF_PATH, 'w') as fw:
                    globalVar.BASE_CONF.write(fw)
                PrintUtil.success('保存密码成功  :)')
            except Exception as e:
                PrintUtil.info("保存密码失败 :(")
                PrintUtil.error(e)
    else:
        sys.exit(0)
Beispiel #2
0
    def showPassedDetail(self, pid):
        cid = globalVar.BASE_CONF.get('contest', 'cid')

        problem = self.getPassedDetail(cid, pid)
        try:
            problem.code.index('输入描述')
            PrintUtil.info(problem.code)
        except:
            print(problem.problemDetail())
        PrintUtil.success(problem.score)
Beispiel #3
0
def check_login(ojOperate):
    # 判断是否登录
    if not os.path.exists(globalVar.BASE_PATH + ".cookies/" +
                          globalVar.OJ_NAME):
        logo = "" \
               "                                        \n" \
               "   █████╗      ██████╗          ██╗     \n" \
               "   ██╔══██╗    ██╔═══██╗         ██║    \n" \
               "   ███████║    ██║   ██║         ██║    \n" \
               "   ██╔══██║    ██║   ██║    ██   ██║    \n" \
               "   ██║  ██║    ╚██████╔╝    ╚█████╔╝    \n" \
               "   ╚═╝  ╚═╝     ╚═════╝      ╚════╝     \n" \

        PrintUtil.info(logo)
        PrintUtil.info("欢迎使用 aoj ,登录后享受丝滑刷题")
        PrintUtil.info("使用\'aoj help\' 查看帮助信息")
        sys.exit(0)
    elif not ojOperate.isLogin():
        PrintUtil.info('登录失效')
        # 验证用户是否已经保存密码
        try:
            username = globalVar.BASE_CONF.get('user', 'username')
            encodePassword = globalVar.BASE_CONF.get('user', 'password')
            # 解码
            password = base64.b64decode(
                encodePassword.encode('utf-8')).decode('utf-8')
            if username == '' or password == '':
                input_name_pass_login(ojOperate)
            else:
                # 账号密码不为空, 尝试自动登录
                PrintUtil.info('正在尝试重新登录...')
                isSuccess = ojOperate.login(username, password)
                if isSuccess:
                    # 保存cookie
                    RequestUtil.session.cookies.save(ignore_discard=True,
                                                     ignore_expires=True)
                    PrintUtil.success("自动登录成功!")
                else:
                    globalVar.BASE_CONF.set('user', 'password', '')
                    with open(globalVar.BASE_CONF_PATH, 'w') as fw:
                        globalVar.BASE_CONF.write(fw)
                    PrintUtil.error("尝试自动登录失败, 手动登录 :(")
                    input_name_pass_login(ojOperate)
        except KeyboardInterrupt:
            pass
        except:
            PrintUtil.error("登录失败,请稍后重试 :<")
            sys.exit(0)