We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pagination objects for User interface
Flask sqlalchemy pagination objects should be used for the user interface instead of the custom pagination. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `CTFd/teams.py`
Content:
```
1 from flask import Blueprint, redirect, render_template, request, url_for
2 
3 from CTFd.cache import clear_team_session, clear_user_session
4 from CTFd.models import Teams, db
5 from CTFd.utils import config, get_config
6 from CTFd.utils.crypto import verify_password
7 from CTFd.utils.decorators import authed_only, ratelimit
8 from CTFd.utils.decorators.modes import require_team_mode
9 from CTFd.utils.decorators.visibility import (
10     check_account_visibility,
11     check_score_visibility,
12 )
13 from CTFd.utils.helpers import get_errors, get_infos
14 from CTFd.utils.user import get_current_user
15 
16 teams = Blueprint("teams", __name__)
17 
18 
19 @teams.route("/teams")
20 @check_account_visibility
21 @require_team_mode
22 def listing():
23     page = abs(request.args.get("page", 1, type=int))
24     results_per_page = 50
25     page_start = results_per_page * (page - 1)
26     page_end = results_per_page * (page - 1) + results_per_page
27 
28     # TODO: Should teams confirm emails?
29     # if get_config('verify_emails'):
30     #     count = Teams.query.filter_by(verified=True, banned=False).count()
31     #     teams = Teams.query.filter_by(verified=True, banned=False).slice(page_start, page_end).all()
32     # else:
33     count = Teams.query.filter_by(hidden=False, banned=False).count()
34     teams = (
35         Teams.query.filter_by(hidden=False, banned=False)
36         .slice(page_start, page_end)
37         .all()
38     )
39 
40     pages = int(count / results_per_page) + (count % results_per_page > 0)
41     return render_template("teams/teams.html", teams=teams, pages=pages, curr_page=page)
42 
43 
44 @teams.route("/teams/join", methods=["GET", "POST"])
45 @authed_only
46 @require_team_mode
47 @ratelimit(method="POST", limit=10, interval=5)
48 def join():
49     infos = get_infos()
50     errors = get_errors()
51     if request.method == "GET":
52         team_size_limit = get_config("team_size", default=0)
53         if team_size_limit:
54             plural = "" if team_size_limit == 1 else "s"
55             infos.append(
56                 "Teams are limited to {limit} member{plural}".format(
57                     limit=team_size_limit, plural=plural
58                 )
59             )
60         return render_template("teams/join_team.html", infos=infos, errors=errors)
61 
62     if request.method == "POST":
63         teamname = request.form.get("name")
64         passphrase = request.form.get("password", "").strip()
65 
66         team = Teams.query.filter_by(name=teamname).first()
67 
68         if team and verify_password(passphrase, team.password):
69             team_size_limit = get_config("team_size", default=0)
70             if team_size_limit and len(team.members) >= team_size_limit:
71                 errors.append(
72                     "{name} has already reached the team size limit of {limit}".format(
73                         name=team.name, limit=team_size_limit
74                     )
75                 )
76                 return render_template(
77                     "teams/join_team.html", infos=infos, errors=errors
78                 )
79 
80             user = get_current_user()
81             user.team_id = team.id
82             db.session.commit()
83 
84             if len(team.members) == 1:
85                 team.captain_id = user.id
86                 db.session.commit()
87 
88             clear_user_session(user_id=user.id)
89             clear_team_session(team_id=team.id)
90 
91             return redirect(url_for("challenges.listing"))
92         else:
93             errors.append("That information is incorrect")
94             return render_template("teams/join_team.html", infos=infos, errors=errors)
95 
96 
97 @teams.route("/teams/new", methods=["GET", "POST"])
98 @authed_only
99 @require_team_mode
100 def new():
101     infos = get_infos()
102     errors = get_errors()
103     if request.method == "GET":
104         team_size_limit = get_config("team_size", default=0)
105         if team_size_limit:
106             plural = "" if team_size_limit == 1 else "s"
107             infos.append(
108                 "Teams are limited to {limit} member{plural}".format(
109                     limit=team_size_limit, plural=plural
110                 )
111             )
112 
113         return render_template("teams/new_team.html", infos=infos, errors=errors)
114     elif request.method == "POST":
115         teamname = request.form.get("name", "").strip()
116         passphrase = request.form.get("password", "").strip()
117         errors = get_errors()
118 
119         user = get_current_user()
120 
121         existing_team = Teams.query.filter_by(name=teamname).first()
122         if existing_team:
123             errors.append("That team name is already taken")
124         if not teamname:
125             errors.append("That team name is invalid")
126 
127         if errors:
128             return render_template("teams/new_team.html", errors=errors)
129 
130         team = Teams(name=teamname, password=passphrase, captain_id=user.id)
131 
132         db.session.add(team)
133         db.session.commit()
134 
135         user.team_id = team.id
136         db.session.commit()
137 
138         clear_user_session(user_id=user.id)
139         clear_team_session(team_id=team.id)
140 
141         return redirect(url_for("challenges.listing"))
142 
143 
144 @teams.route("/team")
145 @authed_only
146 @require_team_mode
147 def private():
148     user = get_current_user()
149     if not user.team_id:
150         return render_template("teams/team_enrollment.html")
151 
152     team_id = user.team_id
153 
154     team = Teams.query.filter_by(id=team_id).first_or_404()
155     solves = team.get_solves()
156     awards = team.get_awards()
157 
158     place = team.place
159     score = team.score
160 
161     return render_template(
162         "teams/private.html",
163         solves=solves,
164         awards=awards,
165         user=user,
166         team=team,
167         score=score,
168         place=place,
169         score_frozen=config.is_scoreboard_frozen(),
170     )
171 
172 
173 @teams.route("/teams/<int:team_id>")
174 @check_account_visibility
175 @check_score_visibility
176 @require_team_mode
177 def public(team_id):
178     errors = get_errors()
179     team = Teams.query.filter_by(id=team_id, banned=False, hidden=False).first_or_404()
180     solves = team.get_solves()
181     awards = team.get_awards()
182 
183     place = team.place
184     score = team.score
185 
186     if errors:
187         return render_template("teams/public.html", team=team, errors=errors)
188 
189     return render_template(
190         "teams/public.html",
191         solves=solves,
192         awards=awards,
193         team=team,
194         score=score,
195         place=place,
196         score_frozen=config.is_scoreboard_frozen(),
197     )
198
```

Path: `CTFd/users.py`
Content:
```
1 from flask import Blueprint, render_template, request
2 
3 from CTFd.models import Users
4 from CTFd.utils import config
5 from CTFd.utils.decorators import authed_only
6 from CTFd.utils.decorators.visibility import (
7     check_account_visibility,
8     check_score_visibility,
9 )
10 from CTFd.utils.user import get_current_user
11 
12 users = Blueprint("users", __name__)
13 
14 
15 @users.route("/users")
16 @check_account_visibility
17 def listing():
18     page = abs(request.args.get("page", 1, type=int))
19     results_per_page = 50
20     page_start = results_per_page * (page - 1)
21     page_end = results_per_page * (page - 1) + results_per_page
22 
23     count = Users.query.filter_by(banned=False, hidden=False).count()
24     users = (
25         Users.query.filter_by(banned=False, hidden=False)
26         .slice(page_start, page_end)
27         .all()
28     )
29 
30     pages = int(count / results_per_page) + (count % results_per_page > 0)
31     return render_template("users/users.html", users=users, pages=pages, curr_page=page)
32 
33 
34 @users.route("/profile")
35 @users.route("/user")
36 @authed_only
37 def private():
38     user = get_current_user()
39 
40     solves = user.get_solves()
41     awards = user.get_awards()
42 
43     place = user.place
44     score = user.score
45 
46     return render_template(
47         "users/private.html",
48         solves=solves,
49         awards=awards,
50         user=user,
51         score=score,
52         place=place,
53         score_frozen=config.is_scoreboard_frozen(),
54     )
55 
56 
57 @users.route("/users/<int:user_id>")
58 @check_account_visibility
59 @check_score_visibility
60 def public(user_id):
61     user = Users.query.filter_by(id=user_id, banned=False, hidden=False).first_or_404()
62     return render_template("users/public.html", user=user)
63
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/CTFd/teams.py b/CTFd/teams.py
--- a/CTFd/teams.py
+++ b/CTFd/teams.py
@@ -21,24 +21,14 @@
 @require_team_mode
 def listing():
     page = abs(request.args.get("page", 1, type=int))
-    results_per_page = 50
-    page_start = results_per_page * (page - 1)
-    page_end = results_per_page * (page - 1) + results_per_page
-
-    # TODO: Should teams confirm emails?
-    # if get_config('verify_emails'):
-    #     count = Teams.query.filter_by(verified=True, banned=False).count()
-    #     teams = Teams.query.filter_by(verified=True, banned=False).slice(page_start, page_end).all()
-    # else:
-    count = Teams.query.filter_by(hidden=False, banned=False).count()
+
     teams = (
         Teams.query.filter_by(hidden=False, banned=False)
-        .slice(page_start, page_end)
-        .all()
+        .order_by(Teams.id.asc())
+        .paginate(page=page, per_page=50)
     )
 
-    pages = int(count / results_per_page) + (count % results_per_page > 0)
-    return render_template("teams/teams.html", teams=teams, pages=pages, curr_page=page)
+    return render_template("teams/teams.html", teams=teams)
 
 
 @teams.route("/teams/join", methods=["GET", "POST"])
diff --git a/CTFd/users.py b/CTFd/users.py
--- a/CTFd/users.py
+++ b/CTFd/users.py
@@ -16,19 +16,14 @@
 @check_account_visibility
 def listing():
     page = abs(request.args.get("page", 1, type=int))
-    results_per_page = 50
-    page_start = results_per_page * (page - 1)
-    page_end = results_per_page * (page - 1) + results_per_page
 
-    count = Users.query.filter_by(banned=False, hidden=False).count()
     users = (
         Users.query.filter_by(banned=False, hidden=False)
-        .slice(page_start, page_end)
-        .all()
+        .order_by(Users.id.asc())
+        .paginate(page=page, per_page=10)
     )
 
-    pages = int(count / results_per_page) + (count % results_per_page > 0)
-    return render_template("users/users.html", users=users, pages=pages, curr_page=page)
+    return render_template("users/users.html", users=users)
 
 
 @users.route("/profile")

{"golden_diff": "diff --git a/CTFd/teams.py b/CTFd/teams.py\n--- a/CTFd/teams.py\n+++ b/CTFd/teams.py\n@@ -21,24 +21,14 @@\n @require_team_mode\n def listing():\n     page = abs(request.args.get(\"page\", 1, type=int))\n-    results_per_page = 50\n-    page_start = results_per_page * (page - 1)\n-    page_end = results_per_page * (page - 1) + results_per_page\n-\n-    # TODO: Should teams confirm emails?\n-    # if get_config('verify_emails'):\n-    #     count = Teams.query.filter_by(verified=True, banned=False).count()\n-    #     teams = Teams.query.filter_by(verified=True, banned=False).slice(page_start, page_end).all()\n-    # else:\n-    count = Teams.query.filter_by(hidden=False, banned=False).count()\n+\n     teams = (\n         Teams.query.filter_by(hidden=False, banned=False)\n-        .slice(page_start, page_end)\n-        .all()\n+        .order_by(Teams.id.asc())\n+        .paginate(page=page, per_page=50)\n     )\n \n-    pages = int(count / results_per_page) + (count % results_per_page > 0)\n-    return render_template(\"teams/teams.html\", teams=teams, pages=pages, curr_page=page)\n+    return render_template(\"teams/teams.html\", teams=teams)\n \n \n @teams.route(\"/teams/join\", methods=[\"GET\", \"POST\"])\ndiff --git a/CTFd/users.py b/CTFd/users.py\n--- a/CTFd/users.py\n+++ b/CTFd/users.py\n@@ -16,19 +16,14 @@\n @check_account_visibility\n def listing():\n     page = abs(request.args.get(\"page\", 1, type=int))\n-    results_per_page = 50\n-    page_start = results_per_page * (page - 1)\n-    page_end = results_per_page * (page - 1) + results_per_page\n \n-    count = Users.query.filter_by(banned=False, hidden=False).count()\n     users = (\n         Users.query.filter_by(banned=False, hidden=False)\n-        .slice(page_start, page_end)\n-        .all()\n+        .order_by(Users.id.asc())\n+        .paginate(page=page, per_page=10)\n     )\n \n-    pages = int(count / results_per_page) + (count % results_per_page > 0)\n-    return render_template(\"users/users.html\", users=users, pages=pages, curr_page=page)\n+    return render_template(\"users/users.html\", users=users)\n \n \n @users.route(\"/profile\")\n", "issue": "Pagination objects for User interface\nFlask sqlalchemy pagination objects should be used for the user interface instead of the custom pagination. \n", "before_files": [{"content": "from flask import Blueprint, redirect, render_template, request, url_for\n\nfrom CTFd.cache import clear_team_session, clear_user_session\nfrom CTFd.models import Teams, db\nfrom CTFd.utils import config, get_config\nfrom CTFd.utils.crypto import verify_password\nfrom CTFd.utils.decorators import authed_only, ratelimit\nfrom CTFd.utils.decorators.modes import require_team_mode\nfrom CTFd.utils.decorators.visibility import (\n    check_account_visibility,\n    check_score_visibility,\n)\nfrom CTFd.utils.helpers import get_errors, get_infos\nfrom CTFd.utils.user import get_current_user\n\nteams = Blueprint(\"teams\", __name__)\n\n\n@teams.route(\"/teams\")\n@check_account_visibility\n@require_team_mode\ndef listing():\n    page = abs(request.args.get(\"page\", 1, type=int))\n    results_per_page = 50\n    page_start = results_per_page * (page - 1)\n    page_end = results_per_page * (page - 1) + results_per_page\n\n    # TODO: Should teams confirm emails?\n    # if get_config('verify_emails'):\n    #     count = Teams.query.filter_by(verified=True, banned=False).count()\n    #     teams = Teams.query.filter_by(verified=True, banned=False).slice(page_start, page_end).all()\n    # else:\n    count = Teams.query.filter_by(hidden=False, banned=False).count()\n    teams = (\n        Teams.query.filter_by(hidden=False, banned=False)\n        .slice(page_start, page_end)\n        .all()\n    )\n\n    pages = int(count / results_per_page) + (count % results_per_page > 0)\n    return render_template(\"teams/teams.html\", teams=teams, pages=pages, curr_page=page)\n\n\n@teams.route(\"/teams/join\", methods=[\"GET\", \"POST\"])\n@authed_only\n@require_team_mode\n@ratelimit(method=\"POST\", limit=10, interval=5)\ndef join():\n    infos = get_infos()\n    errors = get_errors()\n    if request.method == \"GET\":\n        team_size_limit = get_config(\"team_size\", default=0)\n        if team_size_limit:\n            plural = \"\" if team_size_limit == 1 else \"s\"\n            infos.append(\n                \"Teams are limited to {limit} member{plural}\".format(\n                    limit=team_size_limit, plural=plural\n                )\n            )\n        return render_template(\"teams/join_team.html\", infos=infos, errors=errors)\n\n    if request.method == \"POST\":\n        teamname = request.form.get(\"name\")\n        passphrase = request.form.get(\"password\", \"\").strip()\n\n        team = Teams.query.filter_by(name=teamname).first()\n\n        if team and verify_password(passphrase, team.password):\n            team_size_limit = get_config(\"team_size\", default=0)\n            if team_size_limit and len(team.members) >= team_size_limit:\n                errors.append(\n                    \"{name} has already reached the team size limit of {limit}\".format(\n                        name=team.name, limit=team_size_limit\n                    )\n                )\n                return render_template(\n                    \"teams/join_team.html\", infos=infos, errors=errors\n                )\n\n            user = get_current_user()\n            user.team_id = team.id\n            db.session.commit()\n\n            if len(team.members) == 1:\n                team.captain_id = user.id\n                db.session.commit()\n\n            clear_user_session(user_id=user.id)\n            clear_team_session(team_id=team.id)\n\n            return redirect(url_for(\"challenges.listing\"))\n        else:\n            errors.append(\"That information is incorrect\")\n            return render_template(\"teams/join_team.html\", infos=infos, errors=errors)\n\n\n@teams.route(\"/teams/new\", methods=[\"GET\", \"POST\"])\n@authed_only\n@require_team_mode\ndef new():\n    infos = get_infos()\n    errors = get_errors()\n    if request.method == \"GET\":\n        team_size_limit = get_config(\"team_size\", default=0)\n        if team_size_limit:\n            plural = \"\" if team_size_limit == 1 else \"s\"\n            infos.append(\n                \"Teams are limited to {limit} member{plural}\".format(\n                    limit=team_size_limit, plural=plural\n                )\n            )\n\n        return render_template(\"teams/new_team.html\", infos=infos, errors=errors)\n    elif request.method == \"POST\":\n        teamname = request.form.get(\"name\", \"\").strip()\n        passphrase = request.form.get(\"password\", \"\").strip()\n        errors = get_errors()\n\n        user = get_current_user()\n\n        existing_team = Teams.query.filter_by(name=teamname).first()\n        if existing_team:\n            errors.append(\"That team name is already taken\")\n        if not teamname:\n            errors.append(\"That team name is invalid\")\n\n        if errors:\n            return render_template(\"teams/new_team.html\", errors=errors)\n\n        team = Teams(name=teamname, password=passphrase, captain_id=user.id)\n\n        db.session.add(team)\n        db.session.commit()\n\n        user.team_id = team.id\n        db.session.commit()\n\n        clear_user_session(user_id=user.id)\n        clear_team_session(team_id=team.id)\n\n        return redirect(url_for(\"challenges.listing\"))\n\n\n@teams.route(\"/team\")\n@authed_only\n@require_team_mode\ndef private():\n    user = get_current_user()\n    if not user.team_id:\n        return render_template(\"teams/team_enrollment.html\")\n\n    team_id = user.team_id\n\n    team = Teams.query.filter_by(id=team_id).first_or_404()\n    solves = team.get_solves()\n    awards = team.get_awards()\n\n    place = team.place\n    score = team.score\n\n    return render_template(\n        \"teams/private.html\",\n        solves=solves,\n        awards=awards,\n        user=user,\n        team=team,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n\n\n@teams.route(\"/teams/<int:team_id>\")\n@check_account_visibility\n@check_score_visibility\n@require_team_mode\ndef public(team_id):\n    errors = get_errors()\n    team = Teams.query.filter_by(id=team_id, banned=False, hidden=False).first_or_404()\n    solves = team.get_solves()\n    awards = team.get_awards()\n\n    place = team.place\n    score = team.score\n\n    if errors:\n        return render_template(\"teams/public.html\", team=team, errors=errors)\n\n    return render_template(\n        \"teams/public.html\",\n        solves=solves,\n        awards=awards,\n        team=team,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n", "path": "CTFd/teams.py"}, {"content": "from flask import Blueprint, render_template, request\n\nfrom CTFd.models import Users\nfrom CTFd.utils import config\nfrom CTFd.utils.decorators import authed_only\nfrom CTFd.utils.decorators.visibility import (\n    check_account_visibility,\n    check_score_visibility,\n)\nfrom CTFd.utils.user import get_current_user\n\nusers = Blueprint(\"users\", __name__)\n\n\n@users.route(\"/users\")\n@check_account_visibility\ndef listing():\n    page = abs(request.args.get(\"page\", 1, type=int))\n    results_per_page = 50\n    page_start = results_per_page * (page - 1)\n    page_end = results_per_page * (page - 1) + results_per_page\n\n    count = Users.query.filter_by(banned=False, hidden=False).count()\n    users = (\n        Users.query.filter_by(banned=False, hidden=False)\n        .slice(page_start, page_end)\n        .all()\n    )\n\n    pages = int(count / results_per_page) + (count % results_per_page > 0)\n    return render_template(\"users/users.html\", users=users, pages=pages, curr_page=page)\n\n\n@users.route(\"/profile\")\n@users.route(\"/user\")\n@authed_only\ndef private():\n    user = get_current_user()\n\n    solves = user.get_solves()\n    awards = user.get_awards()\n\n    place = user.place\n    score = user.score\n\n    return render_template(\n        \"users/private.html\",\n        solves=solves,\n        awards=awards,\n        user=user,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n\n\n@users.route(\"/users/<int:user_id>\")\n@check_account_visibility\n@check_score_visibility\ndef public(user_id):\n    user = Users.query.filter_by(id=user_id, banned=False, hidden=False).first_or_404()\n    return render_template(\"users/public.html\", user=user)\n", "path": "CTFd/users.py"}], "after_files": [{"content": "from flask import Blueprint, redirect, render_template, request, url_for\n\nfrom CTFd.cache import clear_team_session, clear_user_session\nfrom CTFd.models import Teams, db\nfrom CTFd.utils import config, get_config\nfrom CTFd.utils.crypto import verify_password\nfrom CTFd.utils.decorators import authed_only, ratelimit\nfrom CTFd.utils.decorators.modes import require_team_mode\nfrom CTFd.utils.decorators.visibility import (\n    check_account_visibility,\n    check_score_visibility,\n)\nfrom CTFd.utils.helpers import get_errors, get_infos\nfrom CTFd.utils.user import get_current_user\n\nteams = Blueprint(\"teams\", __name__)\n\n\n@teams.route(\"/teams\")\n@check_account_visibility\n@require_team_mode\ndef listing():\n    page = abs(request.args.get(\"page\", 1, type=int))\n\n    teams = (\n        Teams.query.filter_by(hidden=False, banned=False)\n        .order_by(Teams.id.asc())\n        .paginate(page=page, per_page=50)\n    )\n\n    return render_template(\"teams/teams.html\", teams=teams)\n\n\n@teams.route(\"/teams/join\", methods=[\"GET\", \"POST\"])\n@authed_only\n@require_team_mode\n@ratelimit(method=\"POST\", limit=10, interval=5)\ndef join():\n    infos = get_infos()\n    errors = get_errors()\n    if request.method == \"GET\":\n        team_size_limit = get_config(\"team_size\", default=0)\n        if team_size_limit:\n            plural = \"\" if team_size_limit == 1 else \"s\"\n            infos.append(\n                \"Teams are limited to {limit} member{plural}\".format(\n                    limit=team_size_limit, plural=plural\n                )\n            )\n        return render_template(\"teams/join_team.html\", infos=infos, errors=errors)\n\n    if request.method == \"POST\":\n        teamname = request.form.get(\"name\")\n        passphrase = request.form.get(\"password\", \"\").strip()\n\n        team = Teams.query.filter_by(name=teamname).first()\n\n        if team and verify_password(passphrase, team.password):\n            team_size_limit = get_config(\"team_size\", default=0)\n            if team_size_limit and len(team.members) >= team_size_limit:\n                errors.append(\n                    \"{name} has already reached the team size limit of {limit}\".format(\n                        name=team.name, limit=team_size_limit\n                    )\n                )\n                return render_template(\n                    \"teams/join_team.html\", infos=infos, errors=errors\n                )\n\n            user = get_current_user()\n            user.team_id = team.id\n            db.session.commit()\n\n            if len(team.members) == 1:\n                team.captain_id = user.id\n                db.session.commit()\n\n            clear_user_session(user_id=user.id)\n            clear_team_session(team_id=team.id)\n\n            return redirect(url_for(\"challenges.listing\"))\n        else:\n            errors.append(\"That information is incorrect\")\n            return render_template(\"teams/join_team.html\", infos=infos, errors=errors)\n\n\n@teams.route(\"/teams/new\", methods=[\"GET\", \"POST\"])\n@authed_only\n@require_team_mode\ndef new():\n    infos = get_infos()\n    errors = get_errors()\n    if request.method == \"GET\":\n        team_size_limit = get_config(\"team_size\", default=0)\n        if team_size_limit:\n            plural = \"\" if team_size_limit == 1 else \"s\"\n            infos.append(\n                \"Teams are limited to {limit} member{plural}\".format(\n                    limit=team_size_limit, plural=plural\n                )\n            )\n\n        return render_template(\"teams/new_team.html\", infos=infos, errors=errors)\n    elif request.method == \"POST\":\n        teamname = request.form.get(\"name\", \"\").strip()\n        passphrase = request.form.get(\"password\", \"\").strip()\n        errors = get_errors()\n\n        user = get_current_user()\n\n        existing_team = Teams.query.filter_by(name=teamname).first()\n        if existing_team:\n            errors.append(\"That team name is already taken\")\n        if not teamname:\n            errors.append(\"That team name is invalid\")\n\n        if errors:\n            return render_template(\"teams/new_team.html\", errors=errors)\n\n        team = Teams(name=teamname, password=passphrase, captain_id=user.id)\n\n        db.session.add(team)\n        db.session.commit()\n\n        user.team_id = team.id\n        db.session.commit()\n\n        clear_user_session(user_id=user.id)\n        clear_team_session(team_id=team.id)\n\n        return redirect(url_for(\"challenges.listing\"))\n\n\n@teams.route(\"/team\")\n@authed_only\n@require_team_mode\ndef private():\n    user = get_current_user()\n    if not user.team_id:\n        return render_template(\"teams/team_enrollment.html\")\n\n    team_id = user.team_id\n\n    team = Teams.query.filter_by(id=team_id).first_or_404()\n    solves = team.get_solves()\n    awards = team.get_awards()\n\n    place = team.place\n    score = team.score\n\n    return render_template(\n        \"teams/private.html\",\n        solves=solves,\n        awards=awards,\n        user=user,\n        team=team,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n\n\n@teams.route(\"/teams/<int:team_id>\")\n@check_account_visibility\n@check_score_visibility\n@require_team_mode\ndef public(team_id):\n    errors = get_errors()\n    team = Teams.query.filter_by(id=team_id, banned=False, hidden=False).first_or_404()\n    solves = team.get_solves()\n    awards = team.get_awards()\n\n    place = team.place\n    score = team.score\n\n    if errors:\n        return render_template(\"teams/public.html\", team=team, errors=errors)\n\n    return render_template(\n        \"teams/public.html\",\n        solves=solves,\n        awards=awards,\n        team=team,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n", "path": "CTFd/teams.py"}, {"content": "from flask import Blueprint, render_template, request\n\nfrom CTFd.models import Users\nfrom CTFd.utils import config\nfrom CTFd.utils.decorators import authed_only\nfrom CTFd.utils.decorators.visibility import (\n    check_account_visibility,\n    check_score_visibility,\n)\nfrom CTFd.utils.user import get_current_user\n\nusers = Blueprint(\"users\", __name__)\n\n\n@users.route(\"/users\")\n@check_account_visibility\ndef listing():\n    page = abs(request.args.get(\"page\", 1, type=int))\n\n    users = (\n        Users.query.filter_by(banned=False, hidden=False)\n        .order_by(Users.id.asc())\n        .paginate(page=page, per_page=10)\n    )\n\n    return render_template(\"users/users.html\", users=users)\n\n\n@users.route(\"/profile\")\n@users.route(\"/user\")\n@authed_only\ndef private():\n    user = get_current_user()\n\n    solves = user.get_solves()\n    awards = user.get_awards()\n\n    place = user.place\n    score = user.score\n\n    return render_template(\n        \"users/private.html\",\n        solves=solves,\n        awards=awards,\n        user=user,\n        score=score,\n        place=place,\n        score_frozen=config.is_scoreboard_frozen(),\n    )\n\n\n@users.route(\"/users/<int:user_id>\")\n@check_account_visibility\n@check_score_visibility\ndef public(user_id):\n    user = Users.query.filter_by(id=user_id, banned=False, hidden=False).first_or_404()\n    return render_template(\"users/public.html\", user=user)\n", "path": "CTFd/users.py"}]}