diff --git a/problems/misc/survey/problem.json b/problems/misc/survey/problem.json new file mode 100644 index 0000000..f018bdc --- /dev/null +++ b/problems/misc/survey/problem.json @@ -0,0 +1,5 @@ +{ + "title": "Survey", + "description": "Take our survey.", + +} \ No newline at end of file diff --git a/server/api/models.py b/server/api/models.py index 5010fc0..87f7a5c 100644 --- a/server/api/models.py +++ b/server/api/models.py @@ -30,6 +30,16 @@ class Users(db.Model): self.admin = False self.registertime = int(time.time()) + def get_invitations(self): + invitations = db.session.query(TeamInvitations).filter_by(rtype=0, toid=self.uid).all() + result = [ ] + for inv in invitations: + team = db.session.query(Teams).filter_by(tid=inv.frid).first() + result.append({ + "team": team.teamname + }) + return result + class Teams(db.Model): tid = db.Column(db.Integer, primary_key=True) teamname = db.Column(db.String(64), unique=True) diff --git a/server/api/team.py b/server/api/team.py index 80b372a..5eb946a 100644 --- a/server/api/team.py +++ b/server/api/team.py @@ -162,6 +162,34 @@ def team_invite_request(): return { "success": 1, "message": "Success!" } +@blueprint.route("/invite/accept", methods=["POST"]) +@api_wrapper +def team_accept_invite(): + params = utils.flat_multi(request.form) + _user = user.get_user().first() + if user.in_team(_user): + raise WebException("You're already in a team!") + + tid = params.get("tid") + _team = get_team(tid=tid).first() + if _team is None: + raise WebException("Team not found.") + + invitation = TeamInvitations.query.filter_by(rtype=0, frid=tid, toid=_user.uid).first() + if invitation is None: + raise WebException("Invitation doesn't exist.") + + with app.app_context(): + _user = Users.query.filter_by(uid=_user.uid).first() + _user.tid = tid + db.session.delete(invitation) + invitation2 = TeamInvitations.query.filter_by(rtype=1, frid=_user.uid, toid=tid).first() + if invitation2 is not None: + db.session.delete(invitation2) + db.session.commit() + + return { "success": 1, "message": "Success!" } + @blueprint.route("/info", methods=["GET"]) @api_wrapper def team_info(): @@ -196,6 +224,9 @@ def team_info(): if logged_in: teamdata["invited"] = team.get_pending_invitations(toid=_user.uid) is not None teamdata["requested"] = team.get_invitation_requests(frid=_user.uid) is not None + else: + if logged_in: + teamdata["invitations"] = _user.get_invitations() return { "success": 1, "team": teamdata } ################## diff --git a/server/api/user.py b/server/api/user.py index ca8f62e..9923c06 100644 --- a/server/api/user.py +++ b/server/api/user.py @@ -166,6 +166,9 @@ def user_info(): userdata["email"] = user.email if user_in_team: userdata["team"] = team.get_team_info(tid=user.tid) + if me and not(user_in_team): + invitations = user.get_invitations() + userdata["invitations"] = invitations return { "success": 1, "user": userdata } ################## diff --git a/web/js/easyctf.js b/web/js/easyctf.js index ba293c8..a58ee9d 100644 --- a/web/js/easyctf.js +++ b/web/js/easyctf.js @@ -317,7 +317,6 @@ var login_form = function() { // team page var create_team = function() { -<<<<<<< HEAD var input = "#create_team input"; var data = $("#create_team").serializeObject(); $(input).attr("disabled", "disabled"); @@ -353,43 +352,6 @@ var add_member = function() { $(input).removeAttr("disabled"); }); }); -======= - var input = "#create_team input"; - var data = $("#create_team").serializeObject(); - $(input).attr("disabled", "disabled"); - api_call("POST", "/api/team/create", data, function(result) { - if (result["success"] == 1) { - location.reload(true); - } else { - display_message("create_team_msg", "danger", result["message"], function() { - $(input).removeAttr("disabled"); - }); - } - }, function(jqXHR, status, error) { - var result = jqXHR["responseText"]; - display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { - $(input).removeAttr("disabled"); - }); - }); -}; - -var add_member = function() { - var input = "#add_member input"; - var data = $("#add_member").serializeObject(); - $(input).attr("disabled", "disabled"); - api_call("POST", "/api/team/invite", data, function(result) { - if (result["success"] == 1) { - location.reload(true); - } else { - $(input).removeAttr("disabled"); - } - }, function(jqXHR, status, error) { - var result = JSON.parse(jqXHR["responseText"]); - display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { - $(input).removeAttr("disabled"); - }); - }); ->>>>>>> d6564d17efae214a3284d1afe243952d90d0b752 }; var rescind_invitation = function(uid) { @@ -411,3 +373,12 @@ var request_invitation = function(tid) { } }); }; + +var accept_invitation = function(tid) { + var data = { "tid": tid }; + api_call("POST", "/api/team/invite/accept", data, function(result) { + if (result["success"] == 1) { + location.reload(true); + } + }); +}; diff --git a/web/pages/profile.html b/web/pages/profile.html index 02c4b87..45aedee 100644 --- a/web/pages/profile.html +++ b/web/pages/profile.html @@ -59,6 +59,7 @@
+
You have {{ user['invitations'].length }} invitation{{ user['invitations'].length==1 ? "" : "s" }}! View »

{{ user['me']==true ? "You're" : "This user is" }} not a part of a team.

Join or create one now »
diff --git a/web/pages/team.html b/web/pages/team.html index 7cb292b..960cb81 100644 --- a/web/pages/team.html +++ b/web/pages/team.html @@ -41,7 +41,8 @@
-

{{ member['name'] }}

+

{{ member['name'] }}

+
Owner

@{{ member['username'] }}

@@ -102,59 +103,73 @@ -

To participate in EasyCTF, you must be on a team. If you'd like to go solo, just create a team by yourself. Read about team eligibility in the rules.

+
+
+ +

To participate in EasyCTF, you must be on a team. If you'd like to go solo, just create a team by yourself. Read about team eligibility in the rules.

-
-
-
-
-
-
-
-
-

Create a Team

-
-
- -
-
-
-
-
-
- -
- + +
+
+
+
+
+
+
+

Create a Team

+
+
+ +
+
+
+
+
+
+ +
+ +
+
-
-
-
-
- -
- +
+
+ +
+ +
+
-
-
-
-
-
- -
-
-
-
- +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+ +

You need an invitation to join another team. If you'd like to request to be a member of their team, go to their team page and click the Request button.

+ - - - -
-

You need an invitation to join another team. If you'd like to request to be a member of their team, go to their team page and click the Request button.