示例#1
0
def purge_db():
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        database.purge_warrior_db()
        flash("Purged the database.")
        return redirect(url_for("admin"))
    else:
        return error_page("It's not nice to try and purge the database " +
                          "without authentication...", 403)
示例#2
0
def purge_db():
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        database.purge_warrior_db()
        flash("Purged the database.")
        return redirect(url_for("admin"))
    else:
        return error_page(
            "It's not nice to try and purge the database " +
            "without authentication...", 403)
示例#3
0
def admin():
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        return render_template('admin.html',
                               n_warriors=len(database.list_warriors_raw()),
                               n_permutations=num_permutations(),
                               locked=database.is_db_locked())
    else:
        return error_page("You are not authorized to access the admin panel.",
                          403)
示例#4
0
def admin():
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        return render_template('admin.html',
                               n_warriors=len(database.list_warriors_raw()),
                               n_permutations=num_permutations(),
                               locked=database.is_db_locked())
    else:
        return error_page("You are not authorized to access the admin panel.",
                          403)
示例#5
0
def acquire_warrior():
    # Try to get the form data
    name = request.form.get('name', False)
    author = request.form.get('author', False)
    if name is False or author is False:
        return error_page("The request is malformed.", 403)
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        warrior = database.get_warrior_by_name(name)
        return render_template("retrieve.html", warrior=warrior)
    else:
        return error_page("You are not authorized to access the source code " +
                          "of warriors.", 403)
示例#6
0
def delete_warrior():
    # Try to get the form data
    name = request.form.get('name', False)
    author = request.form.get('author', False)
    if name is False or author is False:
        return error_page("The request is malformed.", 403)
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        database.delete_warrior_by_name(name)
        flash("Successfully deleted {} by {}.".format(name, author))
        return redirect(url_for('list_warriors'))
    else:
        return error_page("You are not authorized to delete warriors.", 403)
示例#7
0
def delete_warrior():
    # Try to get the form data
    name = request.form.get('name', False)
    author = request.form.get('author', False)
    if name is False or author is False:
        return error_page("The request is malformed.", 403)
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        database.delete_warrior_by_name(name)
        flash("Successfully deleted {} by {}.".format(name, author))
        return redirect(url_for('list_warriors'))
    else:
        return error_page("You are not authorized to delete warriors.", 403)
示例#8
0
def acquire_warrior():
    # Try to get the form data
    name = request.form.get('name', False)
    author = request.form.get('author', False)
    if name is False or author is False:
        return error_page("The request is malformed.", 403)
    # Make sure the user is authenticated. If not, kick them out.
    if authentication.is_authenticated():
        warrior = database.get_warrior_by_name(name)
        return render_template("retrieve.html", warrior=warrior)
    else:
        return error_page(
            "You are not authorized to access the source code " +
            "of warriors.", 403)
示例#9
0
def login():
    # If we don't have form data, simply show the form or the admin page.
    if request.method == 'GET':
        if authentication.is_authenticated():
            return redirect(url_for('admin'))
        else:
            return render_template('login.html')
    # If we do have form data, validate the password and take the appropriate
    #   action
    if request.method == 'POST':
        password = request.form.get('password', '')
        if authentication.check_password(password):
            authentication.login()
            return redirect(url_for('login'))
        else:
            return error_page('The password was incorrect.', 403)
示例#10
0
def login():
    # If we don't have form data, simply show the form or the admin page.
    if request.method == 'GET':
        if authentication.is_authenticated():
            return redirect(url_for('admin'))
        else:
            return render_template('login.html')
    # If we do have form data, validate the password and take the appropriate
    #   action
    if request.method == 'POST':
        password = request.form.get('password', '')
        if authentication.check_password(password):
            authentication.login()
            return redirect(url_for('login'))
        else:
            return error_page('The password was incorrect.', 403)
示例#11
0
def pair_warriors():
    from toroid.pairs import make_pairings
    # Check if we're authenticated
    if authentication.is_authenticated():
        # Try to pair all the warriors in the db
        (raw_pairs, raw_odd_one_out) = make_pairings(
                                    database.list_warriors_raw())
        # See if we got back pairings
        if raw_pairs is False:
            return error_page("Pairing failed. Are there warriors in the db?",
                              500)
        # Place results in the session
        session['raw_pairs'] = raw_pairs
        session['raw_odd_one_out'] = raw_odd_one_out
        return redirect(url_for('show_pairs'))
    else:
        return error_page("You are not authorized to generate pairs.", 403)
示例#12
0
def pair_warriors():
    from toroid.pairs import make_pairings
    # Check if we're authenticated
    if authentication.is_authenticated():
        # Try to pair all the warriors in the db
        (raw_pairs,
         raw_odd_one_out) = make_pairings(database.list_warriors_raw())
        # See if we got back pairings
        if raw_pairs is False:
            return error_page("Pairing failed. Are there warriors in the db?",
                              500)
        # Place results in the session
        session['raw_pairs'] = raw_pairs
        session['raw_odd_one_out'] = raw_odd_one_out
        return redirect(url_for('show_pairs'))
    else:
        return error_page("You are not authorized to generate pairs.", 403)
示例#13
0
def show_pairs():
    if authentication.is_authenticated():
        # Try and get data from the session
        raw_pairs = session.get('raw_pairs', False)
        raw_odd_one_out = session.get('raw_odd_one_out', None)
        if raw_pairs is False or raw_odd_one_out is None:
            return error_page("Your pair data is invalid. Regenerate.", 400)

        # We have data, convert it.
        pairs = wdr.dictpairlist_to_warriorpairlist(raw_pairs)
        if raw_odd_one_out is not False:
            odd_one_out = wdr.dict_to_warrior(raw_odd_one_out)
        else:
            odd_one_out = False

        # OK! Render.
        return render_template('pairs.html',
                               pairs=pairs,
                               odd_one_out=odd_one_out)

    else:
        return error_page("You're not allowed to make pairs. You can't " +
                          "have any to view... why are you here?", 500)
示例#14
0
def show_pairs():
    if authentication.is_authenticated():
        # Try and get data from the session
        raw_pairs = session.get('raw_pairs', False)
        raw_odd_one_out = session.get('raw_odd_one_out', None)
        if raw_pairs is False or raw_odd_one_out is None:
            return error_page("Your pair data is invalid. Regenerate.", 400)

        # We have data, convert it.
        pairs = wdr.dictpairlist_to_warriorpairlist(raw_pairs)
        if raw_odd_one_out is not False:
            odd_one_out = wdr.dict_to_warrior(raw_odd_one_out)
        else:
            odd_one_out = False

        # OK! Render.
        return render_template('pairs.html',
                               pairs=pairs,
                               odd_one_out=odd_one_out)

    else:
        return error_page(
            "You're not allowed to make pairs. You can't " +
            "have any to view... why are you here?", 500)
示例#15
0
def list_warriors():
    return render_template('warrior_list.html',
                           programs=database.list_warriors(),
                           admin=authentication.is_authenticated())
示例#16
0
def list_warriors():
    return render_template('warrior_list.html',
                           programs=database.list_warriors(),
                           admin=authentication.is_authenticated())