diff --git a/src/application.py b/src/application.py index 4d764f5..c239af3 100644 --- a/src/application.py +++ b/src/application.py @@ -2,6 +2,7 @@ import os import requests import sys +import uuid from datetime import datetime import jwt @@ -583,7 +584,7 @@ def create_contest(): end = request.form.get("end") description = request.form.get("description").replace('\r', '').strip() contest_name = request.form.get("contest_name") - scoreboard_key = request.form.get("scoreboard_key") + scoreboard_key = str(uuid.uuid4()) scoreboard_visible = bool(request.form.get("scoreboard_visible")) # Ensure contest ID is valid diff --git a/src/templates/contest/contest.html b/src/templates/contest/contest.html index 20e375f..9087a25 100644 --- a/src/templates/contest/contest.html +++ b/src/templates/contest/contest.html @@ -23,7 +23,8 @@

{{ title }}

href="{{ request.path }}/notify">Notify Participants {% endif %} View CTFtime Scoreboard + href="/api/contest/scoreboard/{{ request.path[9:] }}?key={{ scoreboard_key }}" + target="_blank">View CTFtime Scoreboard {% endif %} diff --git a/src/templates/contest/create.html b/src/templates/contest/create.html index 1df9b7c..b33a08e 100644 --- a/src/templates/contest/create.html +++ b/src/templates/contest/create.html @@ -52,19 +52,8 @@

Create Contest

- +
-
Live scoreboard feed (for CTFtime): /api/contest/scoreboard/?key=
- -
diff --git a/src/tests/test_contest.py b/src/tests/test_contest.py index 9130bb2..7495b6a 100644 --- a/src/tests/test_contest.py +++ b/src/tests/test_contest.py @@ -49,8 +49,7 @@ def test_contest(client, database): 'start': datetime.strftime(datetime.now(), "%Y-%m-%dT%H:%M:%S.%fZ"), 'end': datetime.strftime(datetime.now() + timedelta(600), "%Y-%m-%dT%H:%M:%S.%fZ"), # noqa E501 'description': 'testing contest description', - 'scoreboard_visible': True, - 'scoreboard_key': '00000000-0000-0000-0000-000000000000' + 'scoreboard_visible': True }, follow_redirects=True) assert result.status_code == 200 assert b'Testing Contest' in result.data @@ -241,7 +240,8 @@ def test_contest(client, database): result = client.get('/api/contest/scoreboard/testingcontest?key=' + admin_api) assert result.status_code == 401 - result = client.get('/api/contest/scoreboard/testingcontest?key=00000000-0000-0000-0000-000000000000') # noqa + key = database.execute("SELECT scoreboard_key FROM contests WHERE id='testingcontest'")[0]["scoreboard_key"] + result = client.get('/api/contest/scoreboard/testingcontest?key=' + key) assert result.status_code == 200 assert result.data == b'{"standings": [{"pos": 1, "team": "normal_user", "score": 2}]}' # noqa