Refine UI and bug fix challenge solving

This commit is contained in:
2026-01-05 22:25:31 +00:00
parent 03d5da76d0
commit 43169288b1
2 changed files with 49 additions and 65 deletions

View File

@@ -54,12 +54,10 @@ def load(app):
# Rate Limiting
last_sub = Submissions.query.filter_by(user_id=user.id).order_by(Submissions.date.desc()).first()
if last_sub and (time.time() - last_sub.date.timestamp() < cooldown):
return jsonify({'success': False, 'message': f'Wait {cooldown}s between tries'})
return jsonify({'success': False, 'message': f'Wait {cooldown}s'})
# Optimized Solve Check (Unified User/Team Mode)
# Find unsolved challenges
solve_filter = (Solves.team_id == team.id) if team else (Solves.user_id == user.id)
# Only query unsolved challenges in the specific category
challenges = Challenges.query.filter(
Challenges.category == category,
Challenges.state == 'visible',
@@ -69,22 +67,21 @@ def load(app):
for chall in challenges:
for flag in Flags.query.filter_by(challenge_id=chall.id).all():
try:
# Supports Static, Regex, and Case-Insensitive flags via CTFd internal classes
if get_flag_class(flag.type).compare(flag, provided_flag):
solve = Solves(
user_id=user.id, team_id=team.id if team else None,
challenge_id=chall.id, ip=request.remote_addr, provided=provided_flag
)
db.session.add(solve)
db.session.add(Submissions(
user_id=user.id, team_id=team.id if team else None,
challenge_id=chall.id, ip=request.remote_addr, provided=provided_flag, type='correct'
))
# USE NATIVE CTFd SOLVE LOGIC
# This handles Solves, Submissions, and Scoreboard updates correctly.
chal_class = get_chal_class(chall.type)
chal_class.solve(user=user, team=team, challenge=chall, request=request)
db.session.commit()
return jsonify({'success': True, 'message': f'Correct: {chall.name}'})
return jsonify({
'success': True,
'message': f'Correct! You solved: {chall.name}',
'challenge_id': chall.id # Pass this back to help the JS
})
except Exception: continue
# Record failed attempt for audit/brute-force detection
# Log incorrect submission natively
db.session.add(Submissions(
user_id=user.id, team_id=team.id if team else None,
challenge_id=None, ip=request.remote_addr, provided=provided_flag, type='incorrect'