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

Commit a75f7c1

Browse files
committed
reset logic improved
1 parent e8598ef commit a75f7c1

File tree

4 files changed

+87
-72
lines changed

4 files changed

+87
-72
lines changed

hints/routes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def flags():
4646
flash("You already submitted this flag.", "info")
4747
elif submitted_flag == stages[current_stage]["flag"]:
4848
flash(f"Correct flag for Stage {current_stage}!", "success")
49-
if submitted_flag not in submitted_flags:
49+
if submitted_flag not in submitted_flags: # no duplicates
5050
submitted_flags.append(submitted_flag)
5151
session["submitted_flags"] = submitted_flags
5252

@@ -70,7 +70,7 @@ def flags():
7070
if submitted_flag == stage_data["flag"]: # out of order
7171
flash(
7272
f"That's the flag for stage {stage}, but in the wrong order, try to go back and find the right one", "info")
73-
# current_stage = stage
73+
# current_stage = stage , i decided to not let them proceed to the next stage, but to stay in current one
7474
hint_index = 0
7575
found = True
7676

@@ -152,10 +152,10 @@ def index():
152152
return render_template("index.html", summary=brief, title="CTFlask - Home")
153153

154154

155-
@bp.route("/restart", methods=["GET"])
156-
@bp.route("/restart.html", methods=["GET"])
157-
@bp.route("/reset", methods=["GET"])
158-
@bp.route("/reset.html", methods=["GET"])
155+
@bp.route("/restart", methods=["POST"])
156+
@bp.route("/restart.html", methods=["POST"])
157+
@bp.route("/reset", methods=["POST"])
158+
@bp.route("/reset.html", methods=["POST"])
159159
def restart():
160160
[session.pop(key, None)
161161
for key in list(session.keys())] # clear the session

hints/static/css/style.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ body {
3636
margin-left: 20px;
3737
}
3838

39-
input{
39+
input {
4040
max-width: 500px;
4141
min-width: 100px;
42-
}
43-
42+
}

hints/static/js/flags.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
document.getElementById("resetButton").addEventListener("click", function(event) {
2+
let confirmAction = confirm("Are you sure you want to reset your progress? This action cannot be undone.");
3+
4+
if (!confirmAction) {
5+
event.preventDefault(); // Prevent form submission if the user cancels
6+
}
7+
});

hints/templates/flags.html

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,90 @@
11
{% extends "layout.html" %}
22

33
{#<!-- Exports header and navbar from header.html -->#}
4-
{% block title %}{{ title }}{% endblock %}
4+
{% block title %}{{ title }}{% endblock %}
55

66
{% block head %}
77
{{ super() }}
88

99
{% endblock %}
1010
{% block content %}
11-
<div class="container mt-5">
12-
<h1 class="text-center">CTFlask</h1>
13-
<div class="mt-4">
14-
<h3>Stage {{ stage }}</h3>
15-
<p>Do not submit anything that comes before the first "{", ie if it is ColaCo{flag}, just submit {flag}</p>
16-
<form method="POST">
17-
<div class="form-group">
18-
<label for="flag">Enter Flag:</label>
19-
<input type="text" id="flag" name="flag" class="form-control" placeholder="{...}" required>
20-
</div>
21-
<button type="submit" name="submit_flag" class="btn btn-primary">Submit Flag</button>
22-
</form>
11+
<div class="container mt-5">
12+
<h1 class="text-center">CTFlask</h1>
13+
<div class="mt-4">
14+
<h3>Stage {{ stage }}</h3>
15+
<p>Do not submit anything that comes before the first "{", ie if it is ColaCo{flag}, just submit {flag}</p>
16+
<form method="POST">
17+
<div class="form-group">
18+
<label for="flag">Enter Flag:</label>
19+
<input type="text" id="flag" name="flag" class="form-control" placeholder="{...}" required>
20+
</div>
21+
<button type="submit" name="submit_flag" class="btn btn-primary">Submit Flag</button>
22+
</form>
2323

24-
<h5>Notes</h5>
25-
{% if notes is defined and notes %}
26-
<p>{{ notes }}</p>
27-
{% endif %}
24+
<h5>Notes</h5>
25+
{% if notes is defined and notes %}
26+
<p>{{ notes }}</p>
27+
{% endif %}
2828

29-
</div>
30-
{% with messages = get_flashed_messages(with_categories=true) %}
31-
{% if messages is defined and messages %}
32-
<div class="mt-4">
33-
{% for category, message in messages %}
34-
<div class="alert alert-{{ category }}" >{{ message }}</div>
29+
</div>
30+
{% with messages = get_flashed_messages(with_categories=true) %}
31+
{% if messages is defined and messages %}
32+
<div class="mt-4">
33+
{% for category, message in messages %}
34+
<div class="alert alert-{{ category }}">{{ message }}</div>
35+
{% endfor %}
36+
</div>
37+
{% endif %}
38+
{% endwith %}
39+
<div class="mt-4">
40+
<h4>Hints</h4>
41+
{% if hints is defined and hints %}
42+
<ul>
43+
{% for hint in hints %}
44+
<li>{{ hint }}</li>
3545
{% endfor %}
36-
</div>
46+
</ul>
47+
{% else %}
48+
<p>No hints revealed yet.</p>
3749
{% endif %}
38-
{% endwith %}
39-
<div class="mt-4">
40-
<h4>Hints</h4>
41-
{% if hints is defined and hints %}
42-
<ul>
43-
{% for hint in hints %}
44-
<li>{{ hint }}</li>
45-
{% endfor %}
46-
</ul>
47-
{% else %}
48-
<p>No hints revealed yet.</p>
49-
{% endif %}
50-
51-
<form method="POST">
52-
<button type="input" name="reveal_hint" class="btn btn-secondary" value="d">Reveal Next Hint</button>
53-
</form>
54-
55-
{#<!-- comment {% if hint_index < num_hints-1 %}
50+
51+
<form method="POST">
52+
<button type="input" name="reveal_hint" class="btn btn-secondary" value="d">Reveal Next Hint</button>
53+
</form>
54+
55+
{#<!-- comment {% if hint_index < num_hints-1 %}
5656
-->
57-
<form method="POST">
58-
<button type="submit" name="reveal_hint" class="btn btn-secondary">Reveal Next Hint</button>
59-
</form>
60-
<!-- {% endif %} -->#}
61-
</div>
57+
<form method="POST">
58+
<button type="submit" name="reveal_hint" class="btn btn-secondary">Reveal Next Hint</button>
59+
</form>
60+
<!-- {% endif %} -->#}
61+
</div>
6262

63-
<div class="mt-4">
64-
<h4>Previously Submitted Flags</h4>
65-
{% if submitted_flags is defined and submitted_flags %}
66-
<ul>
67-
{% for flag in submitted_flags %}
68-
<li>{{ flag }}</li>
69-
{% endfor %}
70-
</ul>
71-
{% else %}
72-
<p>No flags submitted yet.</p>
73-
{% endif %}
74-
</div>
75-
<div class="mt-4">
76-
<a href="{{ url_for('ctf.restart') }}" class="btn btn-danger">Restart Challenge</a>
77-
</div>
63+
<div class="mt-4">
64+
<h4>Previously Submitted Flags</h4>
65+
{% if submitted_flags is defined and submitted_flags %}
66+
<ul>
67+
{% for flag in submitted_flags %}
68+
<li>{{ flag }}</li>
69+
{% endfor %}
70+
</ul>
71+
{% else %}
72+
<p>No flags submitted yet.</p>
73+
{% endif %}
74+
</div>
75+
{#<!-- <div class="mt-4">
76+
<p>(danger) You will lose all progress and saved flags on this site: </p>
77+
<a href="{{ url_for('ctf.restart') }}" class="btn btn-danger" id="reset">Reset Progress</a>
78+
</div> -->#}
79+
<div class="mt-4">
80+
<form id="resetForm" action="{{ url_for('ctf.restart') }}" method="POST">
81+
<button type="submit" id="resetButton" class="btn btn-danger" role="button">Reset Progress</button>
82+
</form>
7883
</div>
7984

80-
{% endblock %}
85+
</div>
86+
87+
<script src="{{ url_for('static', filename='js/flags.js') }}"></script>
88+
8189

90+
{% endblock %}

0 commit comments

Comments
 (0)