summaryrefslogtreecommitdiff
path: root/nick.py
diff options
context:
space:
mode:
authorMarkku Okkonen <mokkonen@local>2023-11-10 15:06:45 +0200
committerMarkku Okkonen <mokkonen@local>2023-11-10 15:06:45 +0200
commit8128427a1d667f62ce4888fe2921ca12b6823deb (patch)
treed24c9f58e3980bc49ca45fece0cceffe9baa3b5d /nick.py
parentfcb6ffc64fa8cf3b57d5960fb75d10107b346e46 (diff)
Database basics and initial workings of nick registeration
Diffstat (limited to 'nick.py')
-rw-r--r--nick.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/nick.py b/nick.py
index e5f7186..438dc8e 100644
--- a/nick.py
+++ b/nick.py
@@ -1,10 +1,28 @@
from app import app
from flask import render_template, session, request, redirect
+import db_actions as D
-@app.route("/nick",methods=["POST"])
-def set_nick():
+
+@app.route("/new_nick",methods=["POST"])
+def new_nick():
nick = request.form["nick"]
- session["nick"] = nick
- return redirect("/")
-
-
+ 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("/#create")
+
+
+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