diff --git a/CTFd/forms/teams.py b/CTFd/forms/teams.py index c5726190..fc047cad 100644 --- a/CTFd/forms/teams.py +++ b/CTFd/forms/teams.py @@ -38,7 +38,27 @@ class TeamCaptainForm(BaseForm): class TeamSearchForm(BaseForm): field = SelectField( "Search Field", - choices=[("name", "Name"), ("id", "ID"), ("affiliation", "Affiliation")], + choices=[ + ("name", "Name"), + ("id", "ID"), + ("affiliation", "Affiliation"), + ("website", "Website"), + ], + default="name", + validators=[InputRequired()], + ) + q = StringField("Parameter", validators=[InputRequired()]) + submit = SubmitField("Search") + + +class PublicTeamSearchForm(BaseForm): + field = SelectField( + "Search Field", + choices=[ + ("name", "Name"), + ("affiliation", "Affiliation"), + ("website", "Website"), + ], default="name", validators=[InputRequired()], ) diff --git a/CTFd/forms/users.py b/CTFd/forms/users.py index 63da61dd..7b47d172 100644 --- a/CTFd/forms/users.py +++ b/CTFd/forms/users.py @@ -15,6 +15,7 @@ class UserSearchForm(BaseForm): ("id", "ID"), ("email", "Email"), ("affiliation", "Affiliation"), + ("website", "Website"), ("ip", "IP Address"), ], default="name", @@ -24,6 +25,21 @@ class UserSearchForm(BaseForm): submit = SubmitField("Search") +class PublicUserSearchForm(BaseForm): + field = SelectField( + "Search Field", + choices=[ + ("name", "Name"), + ("affiliation", "Affiliation"), + ("website", "Website"), + ], + default="name", + validators=[InputRequired()], + ) + q = StringField("Parameter", validators=[InputRequired()]) + submit = SubmitField("Search") + + class UserEditForm(BaseForm): name = StringField("User Name", validators=[InputRequired()]) email = EmailField("Email", validators=[InputRequired()]) diff --git a/CTFd/teams.py b/CTFd/teams.py index ede3984b..962a6316 100644 --- a/CTFd/teams.py +++ b/CTFd/teams.py @@ -20,15 +20,34 @@ teams = Blueprint("teams", __name__) @check_account_visibility @require_team_mode def listing(): - page = abs(request.args.get("page", 1, type=int)) + q = request.args.get("q") + field = request.args.get("field", "name") + filters = [] + + if field not in ("name", "affiliation", "website"): + field = "name" + + if q: + filters.append(getattr(Teams, field).like("%{}%".format(q))) teams = ( Teams.query.filter_by(hidden=False, banned=False) + .filter(*filters) .order_by(Teams.id.asc()) - .paginate(page=page, per_page=50) + .paginate(per_page=50) ) - return render_template("teams/teams.html", teams=teams) + args = dict(request.args) + args.pop("page", 1) + + return render_template( + "teams/teams.html", + teams=teams, + prev_page=url_for(request.endpoint, page=teams.prev_num, **args), + next_page=url_for(request.endpoint, page=teams.next_num, **args), + q=q, + field=field, + ) @teams.route("/teams/join", methods=["GET", "POST"]) diff --git a/CTFd/themes/admin/templates/teams/teams.html b/CTFd/themes/admin/templates/teams/teams.html index 1cde4ca4..84e1dd3d 100644 --- a/CTFd/themes/admin/templates/teams/teams.html +++ b/CTFd/themes/admin/templates/teams/teams.html @@ -28,7 +28,7 @@ {% endif %} - {% with form = Forms.teams.TeamSearchForm() %} + {% with form = Forms.teams.TeamSearchForm(field=field, q=q) %}