mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
Give challenge plugins the ability to specify the response message (#351)
This commit is contained in:
@@ -287,15 +287,16 @@ def chal(chalid):
|
||||
})
|
||||
|
||||
chal_class = get_chal_class(chal.type)
|
||||
if chal_class.solve(chal, provided_key):
|
||||
status, message = chal_class.solve(chal, provided_key)
|
||||
if status: # The challenge plugin says the input is right
|
||||
if utils.ctftime():
|
||||
solve = Solves(teamid=session['id'], chalid=chalid, ip=utils.get_ip(), flag=provided_key)
|
||||
db.session.add(solve)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
logger.info("[{0}] {1} submitted {2} with kpm {3} [CORRECT]".format(*data))
|
||||
return jsonify({'status': 1, 'message': 'Correct'})
|
||||
|
||||
return jsonify({'status': 1, 'message': message})
|
||||
else: # The challenge plugin says the input is wrong
|
||||
if utils.ctftime():
|
||||
wrong = WrongKeys(teamid=session['id'], chalid=chalid, ip=utils.get_ip(), flag=provided_key)
|
||||
db.session.add(wrong)
|
||||
@@ -308,9 +309,11 @@ def chal(chalid):
|
||||
tries_str = 'tries'
|
||||
if attempts_left == 1:
|
||||
tries_str = 'try'
|
||||
return jsonify({'status': 0, 'message': 'Incorrect. You have {} {} remaining.'.format(attempts_left, tries_str)})
|
||||
if message[-1] not in '!().;?[]\{\}': # Add a punctuation mark if there isn't one
|
||||
message = message + '.'
|
||||
return jsonify({'status': 0, 'message': '{} You have {} {} remaining.'.format(message, attempts_left, tries_str)})
|
||||
else:
|
||||
return jsonify({'status': 0, 'message': 'Incorrect'})
|
||||
return jsonify({'status': 0, 'message': message})
|
||||
|
||||
# Challenge already solved
|
||||
else:
|
||||
|
||||
@@ -16,8 +16,8 @@ class CTFdStandardChallenge(BaseChallenge):
|
||||
chal_keys = Keys.query.filter_by(chal=chal.id).all()
|
||||
for chal_key in chal_keys:
|
||||
if get_key_class(chal_key.key_type).compare(chal_key.flag, provided_key):
|
||||
return True
|
||||
return False
|
||||
return True, 'Correct'
|
||||
return False, 'Incorrect'
|
||||
|
||||
|
||||
CHALLENGE_CLASSES = {
|
||||
|
||||
Reference in New Issue
Block a user