コード例 #1
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def get_live_server_time():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "THE2TIME3IS4NOW5"):
        return "7h3-u53r5-71m3-15-c0rr3c7"
    else:
        return abort(403)
コード例 #2
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def failure():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "OH2NO3YOU4FAILED"):
        flash("You ran out of time! Try again.")
        return url_for("main_page")

    else:
        return abort(403)
コード例 #3
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def redirect_to_the_challenge():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "REDIRECTING2TO3THE4CHALLENGE5NOW"):
        session["starting_challenge"] = True
        return url_for("the_challenge")

    else:
        return abort(403)
コード例 #4
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def check_connection():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "INTERNET2CONNECT"):
        # Check if the user can access the example domain by IANA
        if check_internet_connection():
            return "y0u-4r3-c0nn3c73d!"
        else:
            return "y0u-4r3-n07-c0nn3c73d"
    else:
        return abort(403)
コード例 #5
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def success_handler():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)
    user_id = request.args.get("user_id", None, type=str)
    time_remaining = request.args.get("time_remaining", None, type=float)

    # Check the key
    if verify_otp(key, "CONGRATULATIONS2YOU3COMPLETED4THE5CHALLENGE6YAY7"):
        # Save the time remaining to the JSON file
        with open(SUCCESS_TIMES_FILE, "r") as infile:
            if len(infile.read()) > 5:
                infile.seek(0)  # Move file pointer to the front of the file
                success_times = json.load(infile)
            else:
                success_times = {}
            infile.close()

        # Try to get an existing time
        try:
            existing_time = success_times[user_id]

        except KeyError:
            existing_time = 0

        # Round the obtained time
        new_time = round(time_remaining, 4)

        # Get the best time
        best_time = max(new_time, existing_time)

        # If the new time is not the best time show a popup
        if best_time != new_time:
            flash(
                f"The time left for this attempt is {new_time} seconds, which unfortunately did not beat your best "
                f"time.")

        # Save the best time to the success times' dictionary
        success_times[user_id] = best_time

        # Write the updated dictionary to the file
        with open(SUCCESS_TIMES_FILE, "w") as outfile:
            json.dump(success_times, outfile)
            outfile.close()

        # Return the success page
        return url_for("success", userid=user_id)

    else:
        return abort(403)
コード例 #6
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def start_challenge():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "START2CHALLENGE3"):
        # Clear data
        clear_user_data()

        # Start the quiz
        session["quiz_starting"] = True
        return url_for(
            "load_challenge")  # Load the url into the javascript script
    else:
        return abort(403)
コード例 #7
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def check_answer():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)
    question_no = request.args.get("question_no", None, type=int)
    user_answer = request.args.getlist(
        "user_answer[]"
    )  # Gets all the elements that has this tag and puts it in a list

    # Check the key
    if verify_otp(key, "I2WANT3TO4CHECK5MY6ANSWER7CAN2YOU3CHECK4"):
        # Get the correct answer
        answer = session["answers"][question_no - 1]

        # Process the user's answer
        processed_user_answer = process_user_answer(user_answer)

        # Check user's answer
        correct = check_user_answer(processed_user_answer, answer)

        return jsonify(correct=correct)
    else:
        return abort(403)
コード例 #8
0
ファイル: __init__.py プロジェクト: Ryan-Kan/The-Challenge
def setup_questions():
    # Get the page's arguments
    key = request.args.get("key", None, type=str)

    # Check the key
    if verify_otp(key, "SETUP2QUESTIONS3"):
        # Setup question bank
        question_handler = QuestionsHandler()

        # Setup the questions
        generated_questions, input_field_prefixes, answers = question_handler.setup_questions(
        )

        # Get the image from Q4
        q4_image_data = generated_questions[3][1]

        # Fix that entry to be only the question string
        generated_questions[3] = generated_questions[3][0]

        # Save questions' data to the session
        questions_and_prefixes = {
            "questions": generated_questions,
            "prefixes": input_field_prefixes
        }

        session["questions_and_prefixes"] = json.dumps(
            questions_and_prefixes)  # Will be used in the JS script
        session[
            "Q4_image"] = q4_image_data  # Has to be handled separately due to its large size
        session[
            "answers"] = answers  # Needs to be kept separate to prevent security leaks

        # Return the json object
        return jsonify(questions=generated_questions)

    else:
        return abort(403)