We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Users cant solve challenge after changing to user mode
**Environment**:

- CTFd Version/Commit: 3.7.0
- Operating System: Ubuntu 22.04.3 LTS
- Web Browser and Version: Bug is occurs in Newest Chrome, Chromium and Firefox. Not tested more.

**What happened?**
Some of our users was not able to submit correct flag to solve the challenge. This occurred for after we swapped to user mode for one of our events, our ctfd instance is usually in Team mode. We narrowed it down to being because the teams still exist, making some users unable to get a solve because they are in a "hidden" team where one of their team members already had solved the challenge. 

**What did you expect to happen?**
Expected to be able to swap to user mode, and be able to have all users solve all challenges, so we dont have to create new teams and users every time we would like to swap mode.

**How to reproduce your issue**
Create a few users in the same team. 
Swap to user mode.
Have one of the users solve a challenge.
Try to solve the same challenge with one of the other users.

**Any associated stack traces or error logs**
n/a


--- 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/admin/__init__.py`
Content:
```
1 import csv  # noqa: I001
2 import datetime
3 import os
4 from io import StringIO
5 
6 from flask import Blueprint, abort
7 from flask import current_app as app
8 from flask import (
9     jsonify,
10     redirect,
11     render_template,
12     render_template_string,
13     request,
14     send_file,
15     url_for,
16 )
17 
18 admin = Blueprint("admin", __name__)
19 
20 # isort:imports-firstparty
21 from CTFd.admin import challenges  # noqa: F401,I001
22 from CTFd.admin import notifications  # noqa: F401,I001
23 from CTFd.admin import pages  # noqa: F401,I001
24 from CTFd.admin import scoreboard  # noqa: F401,I001
25 from CTFd.admin import statistics  # noqa: F401,I001
26 from CTFd.admin import submissions  # noqa: F401,I001
27 from CTFd.admin import teams  # noqa: F401,I001
28 from CTFd.admin import users  # noqa: F401,I001
29 from CTFd.cache import (
30     cache,
31     clear_challenges,
32     clear_config,
33     clear_pages,
34     clear_standings,
35 )
36 from CTFd.models import (
37     Awards,
38     Challenges,
39     Configs,
40     Notifications,
41     Pages,
42     Solves,
43     Submissions,
44     Teams,
45     Tracking,
46     Unlocks,
47     Users,
48     db,
49 )
50 from CTFd.utils import config as ctf_config
51 from CTFd.utils import get_app_config, get_config, set_config
52 from CTFd.utils.csv import dump_csv, load_challenges_csv, load_teams_csv, load_users_csv
53 from CTFd.utils.decorators import admins_only
54 from CTFd.utils.exports import background_import_ctf
55 from CTFd.utils.exports import export_ctf as export_ctf_util
56 from CTFd.utils.security.auth import logout_user
57 from CTFd.utils.uploads import delete_file
58 from CTFd.utils.user import is_admin
59 
60 
61 @admin.route("/admin", methods=["GET"])
62 def view():
63     if is_admin():
64         return redirect(url_for("admin.statistics"))
65     return redirect(url_for("auth.login"))
66 
67 
68 @admin.route("/admin/plugins/<plugin>", methods=["GET", "POST"])
69 @admins_only
70 def plugin(plugin):
71     if request.method == "GET":
72         plugins_path = os.path.join(app.root_path, "plugins")
73 
74         config_html_plugins = [
75             name
76             for name in os.listdir(plugins_path)
77             if os.path.isfile(os.path.join(plugins_path, name, "config.html"))
78         ]
79 
80         if plugin in config_html_plugins:
81             config_html = open(
82                 os.path.join(app.root_path, "plugins", plugin, "config.html")
83             ).read()
84             return render_template_string(config_html)
85         abort(404)
86     elif request.method == "POST":
87         for k, v in request.form.items():
88             if k == "nonce":
89                 continue
90             set_config(k, v)
91         with app.app_context():
92             clear_config()
93         return "1"
94 
95 
96 @admin.route("/admin/import", methods=["GET", "POST"])
97 @admins_only
98 def import_ctf():
99     if request.method == "GET":
100         start_time = cache.get("import_start_time")
101         end_time = cache.get("import_end_time")
102         import_status = cache.get("import_status")
103         import_error = cache.get("import_error")
104         return render_template(
105             "admin/import.html",
106             start_time=start_time,
107             end_time=end_time,
108             import_status=import_status,
109             import_error=import_error,
110         )
111     elif request.method == "POST":
112         backup = request.files["backup"]
113         background_import_ctf(backup)
114         return redirect(url_for("admin.import_ctf"))
115 
116 
117 @admin.route("/admin/export", methods=["GET", "POST"])
118 @admins_only
119 def export_ctf():
120     backup = export_ctf_util()
121     ctf_name = ctf_config.ctf_name()
122     day = datetime.datetime.now().strftime("%Y-%m-%d_%T")
123     full_name = "{}.{}.zip".format(ctf_name, day)
124     return send_file(
125         backup, cache_timeout=-1, as_attachment=True, attachment_filename=full_name
126     )
127 
128 
129 @admin.route("/admin/import/csv", methods=["POST"])
130 @admins_only
131 def import_csv():
132     csv_type = request.form["csv_type"]
133     # Try really hard to load data in properly no matter what nonsense Excel gave you
134     raw = request.files["csv_file"].stream.read()
135     try:
136         csvdata = raw.decode("utf-8-sig")
137     except UnicodeDecodeError:
138         try:
139             csvdata = raw.decode("cp1252")
140         except UnicodeDecodeError:
141             csvdata = raw.decode("latin-1")
142     csvfile = StringIO(csvdata)
143 
144     loaders = {
145         "challenges": load_challenges_csv,
146         "users": load_users_csv,
147         "teams": load_teams_csv,
148     }
149 
150     loader = loaders[csv_type]
151     reader = csv.DictReader(csvfile)
152     success = loader(reader)
153     if success is True:
154         return redirect(url_for("admin.config"))
155     else:
156         return jsonify(success), 500
157 
158 
159 @admin.route("/admin/export/csv")
160 @admins_only
161 def export_csv():
162     table = request.args.get("table")
163 
164     output = dump_csv(name=table)
165 
166     return send_file(
167         output,
168         as_attachment=True,
169         max_age=-1,
170         download_name="{name}-{table}.csv".format(
171             name=ctf_config.ctf_name(), table=table
172         ),
173     )
174 
175 
176 @admin.route("/admin/config", methods=["GET", "POST"])
177 @admins_only
178 def config():
179     # Clear the config cache so that we don't get stale values
180     clear_config()
181 
182     configs = Configs.query.all()
183     configs = {c.key: get_config(c.key) for c in configs}
184 
185     themes = ctf_config.get_themes()
186 
187     # Remove current theme but ignore failure
188     try:
189         themes.remove(get_config("ctf_theme"))
190     except ValueError:
191         pass
192 
193     force_html_sanitization = get_app_config("HTML_SANITIZATION")
194 
195     return render_template(
196         "admin/config.html",
197         themes=themes,
198         **configs,
199         force_html_sanitization=force_html_sanitization
200     )
201 
202 
203 @admin.route("/admin/reset", methods=["GET", "POST"])
204 @admins_only
205 def reset():
206     if request.method == "POST":
207         require_setup = False
208         logout = False
209         next_url = url_for("admin.statistics")
210 
211         data = request.form
212 
213         if data.get("pages"):
214             _pages = Pages.query.all()
215             for p in _pages:
216                 for f in p.files:
217                     delete_file(file_id=f.id)
218 
219             Pages.query.delete()
220 
221         if data.get("notifications"):
222             Notifications.query.delete()
223 
224         if data.get("challenges"):
225             _challenges = Challenges.query.all()
226             for c in _challenges:
227                 for f in c.files:
228                     delete_file(file_id=f.id)
229             Challenges.query.delete()
230 
231         if data.get("accounts"):
232             Users.query.delete()
233             Teams.query.delete()
234             require_setup = True
235             logout = True
236 
237         if data.get("submissions"):
238             Solves.query.delete()
239             Submissions.query.delete()
240             Awards.query.delete()
241             Unlocks.query.delete()
242             Tracking.query.delete()
243 
244         if require_setup:
245             set_config("setup", False)
246             cache.clear()
247             logout_user()
248             next_url = url_for("views.setup")
249 
250         db.session.commit()
251 
252         clear_pages()
253         clear_standings()
254         clear_challenges()
255         clear_config()
256 
257         if logout is True:
258             cache.clear()
259             logout_user()
260 
261         db.session.close()
262         return redirect(next_url)
263 
264     return render_template("admin/reset.html")
265
```
--- 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/admin/__init__.py b/CTFd/admin/__init__.py
--- a/CTFd/admin/__init__.py
+++ b/CTFd/admin/__init__.py
@@ -28,6 +28,8 @@
 from CTFd.admin import users  # noqa: F401,I001
 from CTFd.cache import (
     cache,
+    clear_all_team_sessions,
+    clear_all_user_sessions,
     clear_challenges,
     clear_config,
     clear_pages,
@@ -241,6 +243,13 @@
             Unlocks.query.delete()
             Tracking.query.delete()
 
+        if data.get("user_mode") == "users":
+            db.session.query(Users).update({Users.team_id: None})
+            Teams.query.delete()
+
+            clear_all_user_sessions()
+            clear_all_team_sessions()
+
         if require_setup:
             set_config("setup", False)
             cache.clear()

{"golden_diff": "diff --git a/CTFd/admin/__init__.py b/CTFd/admin/__init__.py\n--- a/CTFd/admin/__init__.py\n+++ b/CTFd/admin/__init__.py\n@@ -28,6 +28,8 @@\n from CTFd.admin import users  # noqa: F401,I001\n from CTFd.cache import (\n     cache,\n+    clear_all_team_sessions,\n+    clear_all_user_sessions,\n     clear_challenges,\n     clear_config,\n     clear_pages,\n@@ -241,6 +243,13 @@\n             Unlocks.query.delete()\n             Tracking.query.delete()\n \n+        if data.get(\"user_mode\") == \"users\":\n+            db.session.query(Users).update({Users.team_id: None})\n+            Teams.query.delete()\n+\n+            clear_all_user_sessions()\n+            clear_all_team_sessions()\n+\n         if require_setup:\n             set_config(\"setup\", False)\n             cache.clear()\n", "issue": "Users cant solve challenge after changing to user mode\n**Environment**:\r\n\r\n- CTFd Version/Commit: 3.7.0\r\n- Operating System: Ubuntu 22.04.3 LTS\r\n- Web Browser and Version: Bug is occurs in Newest Chrome, Chromium and Firefox. Not tested more.\r\n\r\n**What happened?**\r\nSome of our users was not able to submit correct flag to solve the challenge. This occurred for after we swapped to user mode for one of our events, our ctfd instance is usually in Team mode. We narrowed it down to being because the teams still exist, making some users unable to get a solve because they are in a \"hidden\" team where one of their team members already had solved the challenge. \r\n\r\n**What did you expect to happen?**\r\nExpected to be able to swap to user mode, and be able to have all users solve all challenges, so we dont have to create new teams and users every time we would like to swap mode.\r\n\r\n**How to reproduce your issue**\r\nCreate a few users in the same team. \r\nSwap to user mode.\r\nHave one of the users solve a challenge.\r\nTry to solve the same challenge with one of the other users.\r\n\r\n**Any associated stack traces or error logs**\r\nn/a\r\n\n", "before_files": [{"content": "import csv  # noqa: I001\nimport datetime\nimport os\nfrom io import StringIO\n\nfrom flask import Blueprint, abort\nfrom flask import current_app as app\nfrom flask import (\n    jsonify,\n    redirect,\n    render_template,\n    render_template_string,\n    request,\n    send_file,\n    url_for,\n)\n\nadmin = Blueprint(\"admin\", __name__)\n\n# isort:imports-firstparty\nfrom CTFd.admin import challenges  # noqa: F401,I001\nfrom CTFd.admin import notifications  # noqa: F401,I001\nfrom CTFd.admin import pages  # noqa: F401,I001\nfrom CTFd.admin import scoreboard  # noqa: F401,I001\nfrom CTFd.admin import statistics  # noqa: F401,I001\nfrom CTFd.admin import submissions  # noqa: F401,I001\nfrom CTFd.admin import teams  # noqa: F401,I001\nfrom CTFd.admin import users  # noqa: F401,I001\nfrom CTFd.cache import (\n    cache,\n    clear_challenges,\n    clear_config,\n    clear_pages,\n    clear_standings,\n)\nfrom CTFd.models import (\n    Awards,\n    Challenges,\n    Configs,\n    Notifications,\n    Pages,\n    Solves,\n    Submissions,\n    Teams,\n    Tracking,\n    Unlocks,\n    Users,\n    db,\n)\nfrom CTFd.utils import config as ctf_config\nfrom CTFd.utils import get_app_config, get_config, set_config\nfrom CTFd.utils.csv import dump_csv, load_challenges_csv, load_teams_csv, load_users_csv\nfrom CTFd.utils.decorators import admins_only\nfrom CTFd.utils.exports import background_import_ctf\nfrom CTFd.utils.exports import export_ctf as export_ctf_util\nfrom CTFd.utils.security.auth import logout_user\nfrom CTFd.utils.uploads import delete_file\nfrom CTFd.utils.user import is_admin\n\n\n@admin.route(\"/admin\", methods=[\"GET\"])\ndef view():\n    if is_admin():\n        return redirect(url_for(\"admin.statistics\"))\n    return redirect(url_for(\"auth.login\"))\n\n\n@admin.route(\"/admin/plugins/<plugin>\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef plugin(plugin):\n    if request.method == \"GET\":\n        plugins_path = os.path.join(app.root_path, \"plugins\")\n\n        config_html_plugins = [\n            name\n            for name in os.listdir(plugins_path)\n            if os.path.isfile(os.path.join(plugins_path, name, \"config.html\"))\n        ]\n\n        if plugin in config_html_plugins:\n            config_html = open(\n                os.path.join(app.root_path, \"plugins\", plugin, \"config.html\")\n            ).read()\n            return render_template_string(config_html)\n        abort(404)\n    elif request.method == \"POST\":\n        for k, v in request.form.items():\n            if k == \"nonce\":\n                continue\n            set_config(k, v)\n        with app.app_context():\n            clear_config()\n        return \"1\"\n\n\n@admin.route(\"/admin/import\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef import_ctf():\n    if request.method == \"GET\":\n        start_time = cache.get(\"import_start_time\")\n        end_time = cache.get(\"import_end_time\")\n        import_status = cache.get(\"import_status\")\n        import_error = cache.get(\"import_error\")\n        return render_template(\n            \"admin/import.html\",\n            start_time=start_time,\n            end_time=end_time,\n            import_status=import_status,\n            import_error=import_error,\n        )\n    elif request.method == \"POST\":\n        backup = request.files[\"backup\"]\n        background_import_ctf(backup)\n        return redirect(url_for(\"admin.import_ctf\"))\n\n\n@admin.route(\"/admin/export\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef export_ctf():\n    backup = export_ctf_util()\n    ctf_name = ctf_config.ctf_name()\n    day = datetime.datetime.now().strftime(\"%Y-%m-%d_%T\")\n    full_name = \"{}.{}.zip\".format(ctf_name, day)\n    return send_file(\n        backup, cache_timeout=-1, as_attachment=True, attachment_filename=full_name\n    )\n\n\n@admin.route(\"/admin/import/csv\", methods=[\"POST\"])\n@admins_only\ndef import_csv():\n    csv_type = request.form[\"csv_type\"]\n    # Try really hard to load data in properly no matter what nonsense Excel gave you\n    raw = request.files[\"csv_file\"].stream.read()\n    try:\n        csvdata = raw.decode(\"utf-8-sig\")\n    except UnicodeDecodeError:\n        try:\n            csvdata = raw.decode(\"cp1252\")\n        except UnicodeDecodeError:\n            csvdata = raw.decode(\"latin-1\")\n    csvfile = StringIO(csvdata)\n\n    loaders = {\n        \"challenges\": load_challenges_csv,\n        \"users\": load_users_csv,\n        \"teams\": load_teams_csv,\n    }\n\n    loader = loaders[csv_type]\n    reader = csv.DictReader(csvfile)\n    success = loader(reader)\n    if success is True:\n        return redirect(url_for(\"admin.config\"))\n    else:\n        return jsonify(success), 500\n\n\n@admin.route(\"/admin/export/csv\")\n@admins_only\ndef export_csv():\n    table = request.args.get(\"table\")\n\n    output = dump_csv(name=table)\n\n    return send_file(\n        output,\n        as_attachment=True,\n        max_age=-1,\n        download_name=\"{name}-{table}.csv\".format(\n            name=ctf_config.ctf_name(), table=table\n        ),\n    )\n\n\n@admin.route(\"/admin/config\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef config():\n    # Clear the config cache so that we don't get stale values\n    clear_config()\n\n    configs = Configs.query.all()\n    configs = {c.key: get_config(c.key) for c in configs}\n\n    themes = ctf_config.get_themes()\n\n    # Remove current theme but ignore failure\n    try:\n        themes.remove(get_config(\"ctf_theme\"))\n    except ValueError:\n        pass\n\n    force_html_sanitization = get_app_config(\"HTML_SANITIZATION\")\n\n    return render_template(\n        \"admin/config.html\",\n        themes=themes,\n        **configs,\n        force_html_sanitization=force_html_sanitization\n    )\n\n\n@admin.route(\"/admin/reset\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef reset():\n    if request.method == \"POST\":\n        require_setup = False\n        logout = False\n        next_url = url_for(\"admin.statistics\")\n\n        data = request.form\n\n        if data.get(\"pages\"):\n            _pages = Pages.query.all()\n            for p in _pages:\n                for f in p.files:\n                    delete_file(file_id=f.id)\n\n            Pages.query.delete()\n\n        if data.get(\"notifications\"):\n            Notifications.query.delete()\n\n        if data.get(\"challenges\"):\n            _challenges = Challenges.query.all()\n            for c in _challenges:\n                for f in c.files:\n                    delete_file(file_id=f.id)\n            Challenges.query.delete()\n\n        if data.get(\"accounts\"):\n            Users.query.delete()\n            Teams.query.delete()\n            require_setup = True\n            logout = True\n\n        if data.get(\"submissions\"):\n            Solves.query.delete()\n            Submissions.query.delete()\n            Awards.query.delete()\n            Unlocks.query.delete()\n            Tracking.query.delete()\n\n        if require_setup:\n            set_config(\"setup\", False)\n            cache.clear()\n            logout_user()\n            next_url = url_for(\"views.setup\")\n\n        db.session.commit()\n\n        clear_pages()\n        clear_standings()\n        clear_challenges()\n        clear_config()\n\n        if logout is True:\n            cache.clear()\n            logout_user()\n\n        db.session.close()\n        return redirect(next_url)\n\n    return render_template(\"admin/reset.html\")\n", "path": "CTFd/admin/__init__.py"}], "after_files": [{"content": "import csv  # noqa: I001\nimport datetime\nimport os\nfrom io import StringIO\n\nfrom flask import Blueprint, abort\nfrom flask import current_app as app\nfrom flask import (\n    jsonify,\n    redirect,\n    render_template,\n    render_template_string,\n    request,\n    send_file,\n    url_for,\n)\n\nadmin = Blueprint(\"admin\", __name__)\n\n# isort:imports-firstparty\nfrom CTFd.admin import challenges  # noqa: F401,I001\nfrom CTFd.admin import notifications  # noqa: F401,I001\nfrom CTFd.admin import pages  # noqa: F401,I001\nfrom CTFd.admin import scoreboard  # noqa: F401,I001\nfrom CTFd.admin import statistics  # noqa: F401,I001\nfrom CTFd.admin import submissions  # noqa: F401,I001\nfrom CTFd.admin import teams  # noqa: F401,I001\nfrom CTFd.admin import users  # noqa: F401,I001\nfrom CTFd.cache import (\n    cache,\n    clear_all_team_sessions,\n    clear_all_user_sessions,\n    clear_challenges,\n    clear_config,\n    clear_pages,\n    clear_standings,\n)\nfrom CTFd.models import (\n    Awards,\n    Challenges,\n    Configs,\n    Notifications,\n    Pages,\n    Solves,\n    Submissions,\n    Teams,\n    Tracking,\n    Unlocks,\n    Users,\n    db,\n)\nfrom CTFd.utils import config as ctf_config\nfrom CTFd.utils import get_app_config, get_config, set_config\nfrom CTFd.utils.csv import dump_csv, load_challenges_csv, load_teams_csv, load_users_csv\nfrom CTFd.utils.decorators import admins_only\nfrom CTFd.utils.exports import background_import_ctf\nfrom CTFd.utils.exports import export_ctf as export_ctf_util\nfrom CTFd.utils.security.auth import logout_user\nfrom CTFd.utils.uploads import delete_file\nfrom CTFd.utils.user import is_admin\n\n\n@admin.route(\"/admin\", methods=[\"GET\"])\ndef view():\n    if is_admin():\n        return redirect(url_for(\"admin.statistics\"))\n    return redirect(url_for(\"auth.login\"))\n\n\n@admin.route(\"/admin/plugins/<plugin>\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef plugin(plugin):\n    if request.method == \"GET\":\n        plugins_path = os.path.join(app.root_path, \"plugins\")\n\n        config_html_plugins = [\n            name\n            for name in os.listdir(plugins_path)\n            if os.path.isfile(os.path.join(plugins_path, name, \"config.html\"))\n        ]\n\n        if plugin in config_html_plugins:\n            config_html = open(\n                os.path.join(app.root_path, \"plugins\", plugin, \"config.html\")\n            ).read()\n            return render_template_string(config_html)\n        abort(404)\n    elif request.method == \"POST\":\n        for k, v in request.form.items():\n            if k == \"nonce\":\n                continue\n            set_config(k, v)\n        with app.app_context():\n            clear_config()\n        return \"1\"\n\n\n@admin.route(\"/admin/import\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef import_ctf():\n    if request.method == \"GET\":\n        start_time = cache.get(\"import_start_time\")\n        end_time = cache.get(\"import_end_time\")\n        import_status = cache.get(\"import_status\")\n        import_error = cache.get(\"import_error\")\n        return render_template(\n            \"admin/import.html\",\n            start_time=start_time,\n            end_time=end_time,\n            import_status=import_status,\n            import_error=import_error,\n        )\n    elif request.method == \"POST\":\n        backup = request.files[\"backup\"]\n        background_import_ctf(backup)\n        return redirect(url_for(\"admin.import_ctf\"))\n\n\n@admin.route(\"/admin/export\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef export_ctf():\n    backup = export_ctf_util()\n    ctf_name = ctf_config.ctf_name()\n    day = datetime.datetime.now().strftime(\"%Y-%m-%d_%T\")\n    full_name = \"{}.{}.zip\".format(ctf_name, day)\n    return send_file(\n        backup, cache_timeout=-1, as_attachment=True, attachment_filename=full_name\n    )\n\n\n@admin.route(\"/admin/import/csv\", methods=[\"POST\"])\n@admins_only\ndef import_csv():\n    csv_type = request.form[\"csv_type\"]\n    # Try really hard to load data in properly no matter what nonsense Excel gave you\n    raw = request.files[\"csv_file\"].stream.read()\n    try:\n        csvdata = raw.decode(\"utf-8-sig\")\n    except UnicodeDecodeError:\n        try:\n            csvdata = raw.decode(\"cp1252\")\n        except UnicodeDecodeError:\n            csvdata = raw.decode(\"latin-1\")\n    csvfile = StringIO(csvdata)\n\n    loaders = {\n        \"challenges\": load_challenges_csv,\n        \"users\": load_users_csv,\n        \"teams\": load_teams_csv,\n    }\n\n    loader = loaders[csv_type]\n    reader = csv.DictReader(csvfile)\n    success = loader(reader)\n    if success is True:\n        return redirect(url_for(\"admin.config\"))\n    else:\n        return jsonify(success), 500\n\n\n@admin.route(\"/admin/export/csv\")\n@admins_only\ndef export_csv():\n    table = request.args.get(\"table\")\n\n    output = dump_csv(name=table)\n\n    return send_file(\n        output,\n        as_attachment=True,\n        max_age=-1,\n        download_name=\"{name}-{table}.csv\".format(\n            name=ctf_config.ctf_name(), table=table\n        ),\n    )\n\n\n@admin.route(\"/admin/config\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef config():\n    # Clear the config cache so that we don't get stale values\n    clear_config()\n\n    configs = Configs.query.all()\n    configs = {c.key: get_config(c.key) for c in configs}\n\n    themes = ctf_config.get_themes()\n\n    # Remove current theme but ignore failure\n    try:\n        themes.remove(get_config(\"ctf_theme\"))\n    except ValueError:\n        pass\n\n    force_html_sanitization = get_app_config(\"HTML_SANITIZATION\")\n\n    return render_template(\n        \"admin/config.html\",\n        themes=themes,\n        **configs,\n        force_html_sanitization=force_html_sanitization\n    )\n\n\n@admin.route(\"/admin/reset\", methods=[\"GET\", \"POST\"])\n@admins_only\ndef reset():\n    if request.method == \"POST\":\n        require_setup = False\n        logout = False\n        next_url = url_for(\"admin.statistics\")\n\n        data = request.form\n\n        if data.get(\"pages\"):\n            _pages = Pages.query.all()\n            for p in _pages:\n                for f in p.files:\n                    delete_file(file_id=f.id)\n\n            Pages.query.delete()\n\n        if data.get(\"notifications\"):\n            Notifications.query.delete()\n\n        if data.get(\"challenges\"):\n            _challenges = Challenges.query.all()\n            for c in _challenges:\n                for f in c.files:\n                    delete_file(file_id=f.id)\n            Challenges.query.delete()\n\n        if data.get(\"accounts\"):\n            Users.query.delete()\n            Teams.query.delete()\n            require_setup = True\n            logout = True\n\n        if data.get(\"submissions\"):\n            Solves.query.delete()\n            Submissions.query.delete()\n            Awards.query.delete()\n            Unlocks.query.delete()\n            Tracking.query.delete()\n\n        if data.get(\"user_mode\") == \"users\":\n            db.session.query(Users).update({Users.team_id: None})\n            Teams.query.delete()\n\n            clear_all_user_sessions()\n            clear_all_team_sessions()\n\n        if require_setup:\n            set_config(\"setup\", False)\n            cache.clear()\n            logout_user()\n            next_url = url_for(\"views.setup\")\n\n        db.session.commit()\n\n        clear_pages()\n        clear_standings()\n        clear_challenges()\n        clear_config()\n\n        if logout is True:\n            cache.clear()\n            logout_user()\n\n        db.session.close()\n        return redirect(next_url)\n\n    return render_template(\"admin/reset.html\")\n", "path": "CTFd/admin/__init__.py"}]}