-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathteams.py
51 lines (40 loc) · 1.64 KB
/
teams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Blueprint, g, request, render_template, flash, url_for, redirect
from data import team, challenge
from utils import decorators, ratelimit
import utils
import config
import exceptions
teams = Blueprint("teams", __name__, template_folder="../templates/teams")
# Things that require a team
@teams.route('/team/', methods=["GET", "POST"])
@decorators.login_required
@ratelimit.ratelimit(limit=6, per=120)
def dashboard():
if request.method == "GET":
team_solves = challenge.get_solves(g.team)
team_adjustments = challenge.get_adjustments(g.team)
team_score = sum([i.challenge.points for i in team_solves] + [i.value for i in team_adjustments])
return render_template("team.html", team_solves=team_solves, team_adjustments=team_adjustments, team_score=team_score)
elif request.method == "POST":
team_name = request.form["team_name"].strip()
affiliation = request.form["team_affiliation"].strip()
try:
team.update_team(g.team, team_name, affiliation)
flash("Changes saved.")
except exceptions.ValidationError as e:
flash(str(e))
return redirect(url_for('.dashboard'))
@teams.route('/teamconfirm/', methods=["POST"])
def teamconfirm():
if utils.misc.get_ip() in config.confirm_ip:
team_name = request.form["team_name"].strip()
team_key = request.form["team_key"].strip()
t = team.get_team(name=team_name)
if t is None:
return "invalid", 403
if t.key == team_key:
return "ok", 200
else:
return "invalid", 403
else:
return "unauthorized", 401