def input_grade(self, student_id, section_id, percent_grade, letter_grade): update = (Registration.update( percent_grade=percent_grade, letter_grade=letter_grade).where( Registration.student_id == student_id, Registration.section_id == section_id)) return update.execute()
def post(self): email = request.args['email'] # Gets or creates a new entry for a hacker hacker, created = Hacker.get_or_create( id=request.args['id'], username=request.args['username'], discriminator=request.args['discriminator']) # If the account exists and is verified return an error if not created and hacker.verified: abort(409, message="Hacker already verified") # Get all registration entries under that email entries = Registration.select().where( fn.Lower(Registration.email) == email.lower()).order_by( Registration.submit_time) if entries.exists(): if entries[0].hacker_discord != None and entries[ 0].hacker_discord != hacker: abort(409, message= "Registration verification started with another hacker") # Start hacker verification hacker.verification = secrets.token_hex(8) hacker.verification_expiration = datetime.datetime.now( ) + datetime.timedelta(hours=1) hacker.save() query = Registration.update(hacker_discord=hacker).where( Registration.email == email) # Email hacker! response = mail.send_verification_email(entries[0], hacker.verification) if response: query.execute() res = jsonify({"status": "Email sent!", "code": 0}) res.status_code = 201 return res else: abort(501, message="Unable to send email") else: abort(404, message="Unable to find registration")