From b868d0ba58384fce5a9a45ae153dee9815327d55 Mon Sep 17 00:00:00 2001 From: Senni Heidari Date: Tue, 21 Nov 2023 11:36:12 +0200 Subject: Update directory hierarchy --- routes/set/nick.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 routes/set/nick.py (limited to 'routes/set/nick.py') diff --git a/routes/set/nick.py b/routes/set/nick.py new file mode 100644 index 0000000..67ddeea --- /dev/null +++ b/routes/set/nick.py @@ -0,0 +1,28 @@ +from app import app +from flask import render_template, session, request, redirect +import db_actions as D + + +@app.route("/set/nick",methods=["POST"]) +def new_nick(): + nick = request.form["nick"] + if "id" in session.keys(): + msg = "You already have a nick." + elif D.user_exists(nick): + msg = "Nick is already reserved." + elif msg := invalid_nick(nick): + pass + else: + session["id"] = D.user_new(nick) + return redirect("/") + session["alert"]="Nick in not created: "+msg + return redirect("/#nick") + + +def invalid_nick(nick): + if len(nick)<4: + return "Nick is too short" + if not nick.isalnum(): + return "Only letters and numbers are allowed" + return 0 + \ No newline at end of file -- cgit v1.2.3