From 2bf130581b763819672551c138cc70119005ef93 Mon Sep 17 00:00:00 2001 From: Jannick Date: Fri, 26 Apr 2024 14:40:15 +0200 Subject: Add form validation on join page --- app.py | 19 ++++++++++++++++++- views/join.html | 19 ++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index c07105e..2e6929a 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from bottle import Bottle, run, debug, static_file, request, redirect, response +from bottle import Bottle, run, debug, static_file, request, redirect, response, HTTPError from bottle import jinja2_template as template from oauthlib.oauth2 import WebApplicationClient from requests_oauthlib import OAuth2Session @@ -47,6 +47,23 @@ def callback(): def join_form(): return template("join") +@app.route("/join.html", method="POST") +def join_submission(db): + name = request.forms.get("name") + preferred_role = request.forms.get("preferredRole") + motivation = request.forms.get("motivation") + + if name == None or name.strip() == "": + raise HTTPError(400, "Namefield is empty or missing. ( warning: this is not good )") + if preferred_role == None: + raise HTTPError(400, "Preferred role is empty or missing.") + if preferred_role not in ("dps", "tank", "healer"): + raise HTTPError(400, "Preferred role must be one of the options (DPS, Tank, Healer) ( idiot )") + if motivation == None or motivation.strip() == "": + raise HTTPError(400, "Motivitaion field is empty or missing.") + + db.execute(f"INSERT INTO applications(name, role, motivation) VALUES ({name}, {preferred_role}, {motivation})") + @app.route("//") def server_static(type, filename): return static_file(filename, root=f"./static/{type}/") diff --git a/views/join.html b/views/join.html index d899b2d..784019c 100644 --- a/views/join.html +++ b/views/join.html @@ -2,10 +2,19 @@ {% block head %} + {% endblock %} {% block content %} -