Exam Code Time Controls

This commit is contained in:
Vivek Santayana 2021-11-30 18:16:52 +00:00
parent ee71044421
commit ae3d34e0f2

View File

@ -48,8 +48,13 @@ def start():
test_code = request.form.get('test_code').replace('', '') test_code = request.form.get('test_code').replace('', '')
user_code = request.form.get('user_code') user_code = request.form.get('user_code')
user_code = None if user_code == '' else user_code user_code = None if user_code == '' else user_code
if not db.tests.find_one({'test_code': test_code}): test = db.tests.find_one({'test_code': test_code})
if not test:
return jsonify({'error': 'The exam code you entered is invalid.'}), 400 return jsonify({'error': 'The exam code you entered is invalid.'}), 400
if test['expiry_date'] < datetime.utcnow():
return jsonify({'error': f'The exam code you entered expired on {test["expiry_date"].strftime("%d %b %Y")}.'}), 400
if test['start_date'] > datetime.utcnow():
return jsonify({'error': f'The exam has not yet opened. Your exam code will be valid from {test["start_date"].strftime("%d %b %Y %H:%M")}.'}), 400
entry = { entry = {
'_id': uuid4().hex, '_id': uuid4().hex,
'name': encrypt(name), 'name': encrypt(name),