diff --git a/config.py b/config.py index d012fb0..750c0ee 100644 --- a/config.py +++ b/config.py @@ -63,6 +63,10 @@ if production: def competition_is_running(): return competition_begin < datetime.now() < competition_end + +def competition_has_started(): + return competition_begin < datetime.now() + # Don't touch these. Instead, copy secrets.example to secrets and edit that. import yaml from collections import namedtuple diff --git a/routes/challenges.py b/routes/challenges.py index 1a76bd9..ac1f2a0 100644 --- a/routes/challenges.py +++ b/routes/challenges.py @@ -10,7 +10,7 @@ challenges = Blueprint("challenges", __name__, template_folder="../templates/cha @challenges.route('/challenges/') @decorators.must_be_allowed_to("view challenges") -@decorators.competition_running_required +@decorators.competition_started_required @decorators.confirmed_email_required def index(): stages = challenge.get_stages() @@ -25,7 +25,7 @@ def index(): @challenges.route('/challenges//solves/') @decorators.must_be_allowed_to("view challenge solves") @decorators.must_be_allowed_to("view challenges") -@decorators.competition_running_required +@decorators.competition_started_required @decorators.confirmed_email_required def show_solves(challenge_id): try: diff --git a/utils/decorators.py b/utils/decorators.py index dc94d53..4171cbc 100644 --- a/utils/decorators.py +++ b/utils/decorators.py @@ -48,6 +48,15 @@ def competition_running_required(f): return f(*args, **kwargs) return decorated +def competition_started_required(f): + @wraps(f) + def decorated(*args, **kwargs): + if not config.competition_has_started() and not ("admin" in session and session["admin"]): + flash("The competition hasn't started") + return redirect(url_for('scoreboard.index')) + return f(*args, **kwargs) + return decorated + def admin_required(f): @wraps(f) def decorated(*args, **kwargs):