Skip to content

Commit

Permalink
Closes #240
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed Jan 3, 2025
1 parent 09620c3 commit 46e8956
Show file tree
Hide file tree
Showing 27 changed files with 76 additions and 76 deletions.
32 changes: 16 additions & 16 deletions src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def settings():
@login_required
def changepassword():
if request.method == "GET":
return render_template("auth/changepassword.html")
return render_template("auth/change_password.html")

# Reached using POST

Expand All @@ -497,19 +497,19 @@ def changepassword():
# Ensure passwords were submitted and they match
if not old_password:
flash('Password cannot be blank', 'danger')
return render_template("auth/changepassword.html"), 400
return render_template("auth/change_password.html"), 400
if not new_password or len(new_password) < 8:
flash('New password must be at least 8 characters', 'danger')
return render_template("auth/changepassword.html"), 400
return render_template("auth/change_password.html"), 400
if not confirmation or new_password != confirmation:
flash('Passwords do not match', 'danger')
return render_template("auth/changepassword.html"), 400
return render_template("auth/change_password.html"), 400

# Ensure username exists and password is correct
rows = db.execute("SELECT * FROM users WHERE id=:id", id=session["user_id"])
if len(rows) != 1 or not check_password_hash(rows[0]["password"], old_password):
flash('Incorrect password', 'danger')
return render_template("auth/changepassword.html"), 401
return render_template("auth/change_password.html"), 401

db.execute("UPDATE users SET password=:new WHERE id=:id",
new=generate_password_hash(new_password), id=session["user_id"])
Expand Down Expand Up @@ -550,22 +550,22 @@ def toggle2fa():
@app.route("/forgotpassword", methods=["GET", "POST"])
def forgotpassword():
if request.method == "GET":
return render_template("auth/forgotpassword.html",
return render_template("auth/forgot_password.html",
site_key=app.config['HCAPTCHA_SITE'])

# Reached via POST

email = request.form.get("email")
if not email:
flash('Email cannot be blank', 'danger')
return render_template("auth/forgotpassword.html"), 400
return render_template("auth/forgot_password.html"), 400

# Ensure captcha is valid
if app.config['USE_CAPTCHA']:
if not check_captcha(app.config['HCAPTCHA_SECRET'],
request.form.get('h-captcha-response'),
app.config['HCAPTCHA_SITE']):
return render_template("auth/forgotpassword.html",
return render_template("auth/forgot_password.html",
site_key=app.config['HCAPTCHA_SITE']), 400

rows = db.execute("SELECT * FROM users WHERE email = :email",
Expand All @@ -584,7 +584,7 @@ def forgotpassword():

flash(('If there is an account associated with that email, a password reset email '
'has been sent'), 'success')
return render_template("auth/forgotpassword.html")
return render_template("auth/forgot_password.html")


@app.route('/resetpassword/<token>', methods=['GET', 'POST'])
Expand All @@ -601,17 +601,17 @@ def reset_password_user(token):
return redirect('/forgotpassword')

if request.method == "GET":
return render_template('auth/resetpassword.html')
return render_template('auth/reset_password.html')

password = request.form.get("password")
confirmation = request.form.get("confirmation")

if not password or len(password) < 8:
flash('New password must be at least 8 characters', 'danger')
return render_template("auth/resetpassword.html"), 400
return render_template("auth/reset_password.html"), 400
if not confirmation or password != confirmation:
flash('Passwords do not match', 'danger')
return render_template("auth/resetpassword.html"), 400
return render_template("auth/reset_password.html"), 400

db.execute("UPDATE users SET password=:new WHERE id=:id",
new=generate_password_hash(password), id=user_id)
Expand All @@ -631,7 +631,7 @@ def contests():
"start <= datetime('now') ORDER BY end DESC"))
future = db.execute(
"SELECT * FROM contests WHERE start > datetime('now') ORDER BY start DESC")
return render_template("contest/contests.html",
return render_template("contest/list.html",
past=past, current=current, future=future)


Expand Down Expand Up @@ -729,7 +729,7 @@ def problems():
"SELECT * FROM contests WHERE end > datetime('now') AND start <= datetime('now')"
))

return render_template('problem/problems.html',
return render_template('problem/list.html',
data=data, solved=solved, length=-(-length // 50),
categories=categories, selected=category,
is_ongoing_contest=is_ongoing_contest)
Expand Down Expand Up @@ -773,7 +773,7 @@ def archived_problems():
categories = db.execute("SELECT DISTINCT category FROM problems WHERE status=2")
categories.sort(key=lambda x: x['category'])

return render_template('problem/archived_list.html',
return render_template('problem/list_archived.html',
data=data, solved=solved, length=-(-length // 50),
categories=categories, selected=category)

Expand Down Expand Up @@ -857,7 +857,7 @@ def draft_problems():
data = db.execute("SELECT * FROM problems WHERE status=1 LIMIT 50 OFFSET ?", page)
length = db.execute("SELECT COUNT(*) AS cnt FROM problems WHERE status=1")[0]["cnt"]

return render_template('problem/draft_problems.html',
return render_template('problem/list_draft.html',
data=data, length=-(-length // 50))


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block main %}
<h1>Nonexistent contest</h1>
<div>
The contest with id {{ request.path.split('/')[2] }} does not exist.
This contest does not exist.
</div>
<a href="/">Back to home</a>
{% endblock %}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block main %}
<h1>Nonexistent problem</h1>
<div>
The problem with id {{ request.path.split("/")[4] }} does not exist.
This problem either does not exist or is not published yet.
</div>
<a href="/contest/{{ request.path.split('/')[2] }}">Back to contest</a>
{% endblock %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/templates/error/maintenance.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>Under Maintenance</h1>
<footer>
<hr>
<p class="text-center">
&copy; 2020-2021, {{ CLUB_NAME }}. Source code available
&copy; 2020-2025, {{ CLUB_NAME }}. Source code available
<a href="https://github.com/jdabtieu/CTFOJ">here</a>.
</p>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<footer>
<hr>
<p class="text-center">
&copy; 2020-2024, {{ CLUB_NAME }}.
&copy; 2020-2025, {{ CLUB_NAME }}.
<a href="https://github.com/jdabtieu/CTFOJ">Source Code</a> -
<a href="/terms">Terms of Service</a> -
<a href="/privacy">Privacy Policy</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block main %}
<h1>Nonexistent problem</h1>
<div>
The problem with id {{ request.path.split("/")[2] }} does not exist.
This problem either does not exist or is not published yet.
</div>
<a href="/problems">Back to problems</a>
{% endblock %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ def verify_user():
@perm_required(["ADMIN", "SUPERADMIN", "CONTENT_MANAGER"])
def createannouncement():
if request.method == "GET":
return render_template("admin/createannouncement.html")
return render_template("admin/announcement_create.html")

# Reached via POST

if not request.form.get("name") or not request.form.get("description"):
flash('You have not entered all required fields', 'danger')
return render_template("admin/createannouncement.html"), 400
return render_template("admin/announcement_create.html"), 400

name = request.form.get("name")
description = request.form.get("description").replace('\r', '')
Expand Down Expand Up @@ -324,18 +324,18 @@ def editannouncement(aid):
data[0]["description"] = read_file('metadata/announcements/' + aid + '.md')

if request.method == "GET":
return render_template('admin/editannouncement.html', data=data[0])
return render_template('admin/announcement_edit.html', data=data[0])

# Reached via POST
new_name = request.form.get("name")
new_description = request.form.get("description").replace('\r', '')

if not new_name:
flash('Name cannot be empty', 'danger')
return render_template('admin/editannouncement.html', data=data[0]), 400
return render_template('admin/announcement_edit.html', data=data[0]), 400
if not new_description:
flash('Description cannot be empty', 'danger')
return render_template('admin/editannouncement.html', data=data[0]), 400
return render_template('admin/announcement_edit.html', data=data[0]), 400

# Update database
db.execute("UPDATE announcements SET name=:name WHERE id=:aid",
Expand Down Expand Up @@ -379,7 +379,7 @@ def disable_maintenance():
def edit_homepage():
data = read_file(app.config['HOMEPAGE_FILE'])[2:]
if request.method == "GET":
return render_template("admin/edithomepage.html", data=data)
return render_template("admin/homepage_edit.html", data=data)

# Reached via POST

Expand All @@ -388,7 +388,7 @@ def edit_homepage():

if not content:
flash('To disable the homepage, edit settings.py instead', 'danger')
return render_template("admin/edithomepage.html", data=data), 400
return render_template("admin/homepage_edit.html", data=data), 400
if not layout_method or layout_method not in ["1", "2"]:
layout_method = "1"

Expand Down
Loading

0 comments on commit 46e8956

Please sign in to comment.