Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static/crackme/*
static/solution/*
!static/crackme/.gitkeep
!static/solution/.gitkeep
# Private source archives for auto-validated crackmes (reviewers only)
private/
config/config.json
users.json
.env
Expand Down
22 changes: 20 additions & 2 deletions app/controllers/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import bleach
from app.models.comment import comment_create, comment_by_id, comment_set_spoiler, get_thread_participants
from app.models.solution import get_solution_authors
from app.models.crackme import crackme_by_hexid, crackme_increment_comments
from app.models.crackme import (
crackme_by_hexid, crackme_increment_comments, crackme_is_auto_validated
)
from app.models.notification import notification_add
from app.models.errors import ErrNoResult
from app.services.recaptcha import verify as verify_recaptcha
Expand Down Expand Up @@ -51,6 +53,23 @@ def leave_comment(hexid):
"""Post a comment on a crackme."""
username = session.get('name')

try:
crackme = crackme_by_hexid(hexid)
except ErrNoResult:
flash('Crackme not found.', FLASH_ERROR)
return redirect(f'/crackme/{hexid}')
except Exception as e:
print(f"Error getting crackme: {e}")
flash('Comment creation failed. Please try again later.', FLASH_ERROR)
return redirect(f'/crackme/{hexid}')

if crackme_is_auto_validated(crackme):
flash(
'Comments are disabled for auto-validated crackmes.',
FLASH_ERROR
)
return redirect(f'/crackme/{hexid}')

# Validate required fields
is_valid, missing = validate_required(request.form, ['comment'])
if not is_valid:
Expand Down Expand Up @@ -92,7 +111,6 @@ def leave_comment(hexid):

# Send notification to crackme author and handle @mentions
try:
crackme = crackme_by_hexid(hexid)
crackme_author = crackme.get('author')
crackme_name = crackme['name']

Expand Down
Loading
Loading