From 7d15213a327c9317bbfab65e4dbd7f0cee1d7cb3 Mon Sep 17 00:00:00 2001 From: handsomehow <673712786@qq.com> Date: Tue, 6 Nov 2018 10:15:44 +0800 Subject: [PATCH] username limit support for contest --- account/decorators.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/account/decorators.py b/account/decorators.py index e57b3312..65d94a76 100644 --- a/account/decorators.py +++ b/account/decorators.py @@ -92,6 +92,15 @@ def check_contest_permission(check_type="details"): if self.contest.id not in request.session.get("accessible_contests", []): return self.error("Password is required.") + # username limited + limit_search = re.search(r"limit:[\s]*#.*?#", self.contest.description) + if limit_search is not None: + limit_str = limit_search.group() + limit_str = limit_str[limit_str.index("#")+1:-1] + match_result = re.match(limit_str, user.username) + if match_result is None or (match_result is not None and match_result.group() is not user.username): + return self.error(f"Username not match {limit_str}") + # regular user get contest problems, ranks etc. before contest started if self.contest.status == ContestStatus.CONTEST_NOT_START and check_type != "details": return self.error("Contest has not started yet.")