blob: 438dc8e8a115bad2031f6ebbc45f1b814fa2f3df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
from app import app
from flask import render_template, session, request, redirect
import db_actions as D
@app.route("/new_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("/#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
|