diff --git a/CTFd/challenges.py b/CTFd/challenges.py index 1bda4138..96d9a506 100644 --- a/CTFd/challenges.py +++ b/CTFd/challenges.py @@ -1,7 +1,7 @@ from flask import current_app as app, render_template, request, redirect, abort, jsonify, json as json_mod, url_for, session, Blueprint from CTFd.utils import ctftime, view_after_ctf, authed, unix_time, get_kpm, can_view_challenges, is_admin, get_config -from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys +from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys, Tags import time import re @@ -38,8 +38,9 @@ def chals(): json = {'game':[]} for x in chals: + tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=x[1]).all()] files = [ str(f.location) for f in Files.query.filter_by(chal=x.id).all() ] - json['game'].append({'id':x[1], 'name':x[2], 'value':x[3], 'description':x[4], 'category':x[5], 'files':files}) + json['game'].append({'id':x[1], 'name':x[2], 'value':x[3], 'description':x[4], 'category':x[5], 'files':files, 'tags':tags}) db.session.close() return jsonify(json) diff --git a/CTFd/static/css/style.css b/CTFd/static/css/style.css index 4f64dc1a..508478b2 100644 --- a/CTFd/static/css/style.css +++ b/CTFd/static/css/style.css @@ -227,6 +227,10 @@ table{ border-radius: 0px; } +.chal-tag { + margin: 0 5px 0 5px; +} + .alert { border-radius: 0px; } diff --git a/CTFd/static/js/chalboard.js b/CTFd/static/js/chalboard.js index ad89a52c..3819d80b 100644 --- a/CTFd/static/js/chalboard.js +++ b/CTFd/static/js/chalboard.js @@ -45,22 +45,31 @@ function loadchalbyname(chalname) { } function updateChalWindow(obj) { - window.location.hash = obj.name - $('#chal-window').find('.chal-name').text(obj.name) - $('#chal-window').find('.chal-desc').html(marked(obj.description, {'gfm':true, 'breaks':true})) - $('#chal-window').find('.chal-files').empty(); + window.location.hash = obj.name; + var chal = $('#chal-window'); + chal.find('.chal-name').text(obj.name); + chal.find('.chal-desc').html(marked(obj.description, {'gfm':true, 'breaks':true})); + chal.find('.chal-files').empty(); for (var i = 0; i < obj.files.length; i++) { - filename = obj.files[i].split('/') - filename = filename[filename.length - 1] + filename = obj.files[i].split('/'); + filename = filename[filename.length - 1]; $('#chal-window').find('.chal-files').append("
") - }; + } - $('#chal-window').find('.chal-value').text(obj.value) - $('#chal-window').find('.chal-category').text(obj.category) - $('#chal-window').find('#chal-id').val(obj.id) + var tags = chal.find('.chal-tags'); + tags.empty(); + var tag = "{0}"; + for (var i = 0; i < obj.tags.length; i++){ + var data = tag.format(obj.tags[i]); + tags.append($(data)); + } + + chal.find('.chal-value').text(obj.value); + chal.find('.chal-category').text(obj.category); + chal.find('#chal-id').val(obj.id); var solves = obj.solves == 1 ? " Solve" : " Solves"; - $('#chal-window').find('.chal-solves').text(obj.solves + solves) - $('#answer').val("") + chal.find('.chal-solves').text(obj.solves + solves); + $('#answer').val(""); $('pre code').each(function(i, block) { hljs.highlightBlock(block); @@ -168,7 +177,7 @@ function getsolves(id){ function loadchals() { $.get("/chals", function (data) { - categories = []; + var categories = []; challenges = $.parseJSON(JSON.stringify(data)); $('#challenges-board').html(""); @@ -188,8 +197,8 @@ function loadchals() { }; for (var i = 0; i <= challenges['game'].length - 1; i++) { - chalinfo = challenges['game'][i]; - challenge = chalinfo.category.replace(/ /g,"-").hashCode(); + var chalinfo = challenges['game'][i]; + var challenge = chalinfo.category.replace(/ /g,"-").hashCode(); var chalid = chalinfo.name.replace(/ /g,"-").hashCode(); var catid = chalinfo.category.replace(/ /g,"-").hashCode(); var chalwrap = $("".format(chalid)); diff --git a/CTFd/templates/chals.html b/CTFd/templates/chals.html index 1d2ee4c2..0f30b893 100644 --- a/CTFd/templates/chals.html +++ b/CTFd/templates/chals.html @@ -107,6 +107,7 @@