def attempt(challenge, request): """ This method is used to check whether a given input is right or wrong. It does not make any changes and should return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the user's input from the request itself. :param challenge: The Challenge object from the database :param request: The request the user submitted :return: (boolean, string) """ data = request.form or request.get_json() submission = data["submission"].strip() # flags = Flags.query.filter_by(challenge_id=challenge.id).all() user_id = get_mode() flag = OwlContainers.query.filter_by( user_id=user_id, challenge_id=challenge.id).first() print(flag) subflag = OwlContainers.query.filter_by(flag=submission).first() print(subflag) if subflag: # if get_flag_class(flag.type).compare(flag, submission): try: fflag = flag.flag except Exception as e: fflag = "" if (fflag == submission): return True, "Correct" else: flaguser = Users.query.filter_by(id=user_id).first() subuser = Users.query.filter_by(id=subflag.user_id).first() if (flaguser.name == subuser.name): return False, "Incorrect Challenge" else: message = flaguser.name + " Submitted " + subuser.name + "'s Flag." db.session.add( Notifications(title="Check Found", content=message)) flaguser.banned = True db.session.commit() messages = {"title": "Check Found", "content": message} current_app.events_manager.publish(data=messages, type="notification") return False, "Checked" else: return False, "Incorrect"
def gen_notification(db, title="title", content="content"): notif = Notifications(title=title, content=content) db.session.add(notif) db.session.commit()
def gen_notification(db, title='title', content='content'): notif = Notifications(title=title, content=content) db.session.add(notif) db.session.commit()