Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 00e5d2b

Browse files
authored
Merge pull request #5 from avipars/python-code-format-patches
Fixes by format action
2 parents 9a1d0a4 + 2bc7f3e commit 00e5d2b

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

flags.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"This is the most revealing hint for stage 2.",
1717
],
1818
"notes": "This is a note for stage 2",
19-
2019
},
2120
3: {"flag": "flag{stage3}", "hints": ["Almost there"]},
2221
}
23-

hints/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from flask import Flask
22

3-
43
# from ctf.error_handlers import register_error_handlers # Adjust the
54
# import based on your project structure
65

@@ -23,7 +22,7 @@ def create_app():
2322
# ensure session cookie is secure
2423
app.config["SESSION_COOKIE_SECURE"] = True
2524
app.config["SESSION_PERMANENT"] = True
26-
app.config['PERMANENT_SESSION_LIFETIME'] = 60 #in seconds
25+
app.config["PERMANENT_SESSION_LIFETIME"] = 60 # in seconds
2726
with app.app_context():
2827
from . import routes
2928

@@ -43,4 +42,4 @@ def create_app():
4342

4443
# register_error_handlers(app)
4544
# app.config['referrer_policy'] = 'strict-origin-when-cross-origin'
46-
from hints import routes # nopep8
45+
from hints import routes # nopep8

hints/routes.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

3-
from flask import (Blueprint, flash, redirect, render_template,
4-
request, session, url_for)
3+
from flask import (Blueprint, flash, redirect, render_template, request,
4+
session, url_for)
55
from markupsafe import escape
66

77
from flags import stages # import everything from flags.py
@@ -28,8 +28,8 @@ def flags():
2828
submitted_flags = session["submitted_flags"]
2929
hint_index = session["hint_index"]
3030

31-
32-
# need to verify that the user didn't try to skip stages or trick the system
31+
# need to verify that the user didn't try to skip stages or trick the
32+
# system
3333

3434
if request.method == "POST":
3535
if "submit_flag" in request.form:
@@ -39,23 +39,27 @@ def flags():
3939
if not submitted_flag.isascii():
4040
flash("Invalid flag. Please try again.", "danger")
4141
return redirect(url_for("ctf.flags"))
42-
42+
4343
if submitted_flag in submitted_flags:
4444
flash("You already submitted this flag.", "info")
4545
elif submitted_flag == stages[current_stage]["flag"]:
4646
flash(f"Correct flag for Stage {current_stage}!", "success")
4747
if submitted_flag not in submitted_flags:
4848
submitted_flags.append(submitted_flag)
4949
session["submitted_flags"] = submitted_flags
50-
50+
5151
if current_stage < len(stages):
5252
current_stage += 1
5353
hint_index = 0
5454
elif current_stage == len(stages):
5555
flash(
5656
"You have completed all the stages. Congratulations!",
5757
"success")
58-
return render_template("message.html", title="Congratulations!", message="You have completed all the stages of the CTF. ")
58+
return render_template(
59+
"message.html",
60+
title="Congratulations!",
61+
message="You have completed all the stages of the CTF. ",
62+
)
5963
# if the user has completed all the stages, then flash a
6064
# message
6165
session["current_stage"] = current_stage
@@ -70,18 +74,23 @@ def flags():
7074
current_stage = stage
7175
hint_index = 0
7276
found = True
73-
77+
7478
if submitted_flag not in submitted_flags:
7579
submitted_flags.append(submitted_flag)
7680
session["submitted_flags"] = submitted_flags
77-
78-
# check if they got all the flags (even if they are out of order)
79-
if sorted(submitted_flags) == sorted([stage_data["flag"] for stage_data in stages.values()]):
81+
82+
# check if they got all the flags (even if they are out
83+
# of order)
84+
if sorted(submitted_flags) == sorted(
85+
[stage_data["flag"] for stage_data in stages.values()]
86+
):
8087
flash(
81-
"You have completed all the stages. Congratulations!",
82-
"success",
88+
"You have completed all the stages. Congratulations!", "success", )
89+
return render_template(
90+
"message.html",
91+
title="Congratulations!",
92+
message="You have completed all the stages of the CTF. ",
8393
)
84-
return render_template("message.html", title="Congratulations!", message="You have completed all the stages of the CTF. ")
8594
# if the user has completed all the stages, then flash a
8695
# message
8796
break
@@ -91,27 +100,30 @@ def flags():
91100

92101
elif "reveal_hint" in request.form:
93102
# hint_num = request.form.get("reveal_hint")
94-
if (
95-
hint_index < len(stages[current_stage]["hints"])
103+
if hint_index < len(
104+
stages[current_stage]["hints"]
96105
): # if there are more hints to reveal
97106
hint_index += 1
98107
else:
99108
# if the user exhausted all the hints, have it show from the
100109
# beginning
101110
# hint_index = 0
102111
# flash a message to the user
103-
flash("Exhausted all hints for this stage :( Try harder!", "warning")
112+
flash(
113+
"Exhausted all hints for this stage :( Try harder!", "warning")
104114
# hide the button till they get to next stage
105115
session["hint_index"] = hint_index
106-
hints = stages[current_stage]["hints"][: hint_index]
116+
hints = stages[current_stage]["hints"][:hint_index]
107117
notes = stages[current_stage].get("notes")
108118
return render_template(
109-
"flags.html",title=f"CTFlask - Stage {current_stage}",
119+
"flags.html",
120+
title=f"CTFlask - Stage {current_stage}",
110121
stage=current_stage,
111122
hints=hints,
112123
hint_index=hint_index,
113124
submitted_flags=submitted_flags,
114-
num_hints=len(stages[current_stage]["hints"]),notes=notes
125+
num_hints=len(stages[current_stage]["hints"]),
126+
notes=notes,
115127
)
116128

117129

@@ -127,7 +139,7 @@ def index():
127139
session["current_stage"] = 1
128140
if "hint_index" not in session:
129141
session["hint_index"] = 0
130-
142+
131143
flash("Welcome to the CTF, please read the following:", "info")
132144
brief = """
133145
Using this site is not required to solve the CTF challenge and is not a part of the CTF challenge itself, but a tool to help you keep track of your progress. You need to find the flags on your own and not via this site itself. Good luck!
@@ -176,4 +188,4 @@ def inject_today_date():
176188
"""
177189
used for the footer to display the current year
178190
"""
179-
return {"year": datetime.date.today().year}
191+
return {"year": datetime.date.today().year}

0 commit comments

Comments
 (0)