コード例 #1
0
def hello_world(encrypted: str):
    basic_query = AnswerForm.SubmitForm()
    if request.method == 'GET':
        # stage decrypted
        # basic_query = AnswerForm.SubmitForm()
        if encrypted != 'start':
            code, result = utils.dispatch_final_stage_status(encrypted)
            code = int(code)
            if code == -1:
                return render_template('errors.html')
            if code == 99:
                return redirect('/stage2/start')
            return render_template('index.html',
                                   table_content=render_table(code + 1),
                                   table=1,
                                   option=1,
                                   query_form=basic_query,
                                   question=fetch_question(code + 1),
                                   progress_value=4 * code + 4)
        else:
            # start the game!
            return render_template('index.html',
                                   table_content=render_table(1),
                                   table=1,
                                   option=1,
                                   query_form=basic_query,
                                   question=fetch_question(1),
                                   progress_value=4)
        return render_template('errors.html')
    else:
        question_id = int(request.form.get('question_id'))
        length_limit = int(request.form.get('length_limit'))
        input_answer = request.form.get('InputField')
        if length_limit != len(input_answer):
            flash(
                'Your answer is: {} with length {}, but the length of this point is {}.'
                .format(input_answer, len(input_answer),
                        length_limit), 'error')
            if question_id == 0:
                return redirect('/stage/start')
            encrypted = '{}/{}{}'.format(
                question_id, '1' * (question_id),
                '0' * (config.total_rounds - question_id))
            hex_encrypted = utils.DES_encrypt(encrypted).decode('utf-8')
            return redirect('/stage/{}'.format(hex_encrypted))
        if input_answer != table_content.question_answer[question_id][1]:
            print('[{}]->[{}]'.format(
                input_answer, table_content.question_answer[question_id][1]))
            flash('Your answer is: {}, but it is wrong.'.format(input_answer),
                  'error')
            if question_id == 0:
                return redirect('/stage/start')
            encrypted = '{}/{}{}'.format(
                question_id, '1' * question_id,
                '0' * (config.total_rounds - question_id))
            hex_encrypted = utils.DES_encrypt(encrypted).decode('utf-8')
            return redirect('/stage/{}'.format(hex_encrypted))
        flash('Your answer is: {}, Correct!'.format(input_answer), 'error')
        encrypted = '{}/{}{}'.format(
            question_id + 1, '1' * (question_id + 1),
            '0' * (config.total_rounds - question_id - 1))
        hex_encrypted = utils.DES_encrypt(encrypted).decode('utf-8')
        return redirect('/stage/{}'.format(hex_encrypted))