Skip to content

Commit

Permalink
Update signup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DogukanUrker committed Dec 15, 2023
1 parent d647a90 commit 6996c04
Showing 1 changed file with 59 additions and 70 deletions.
129 changes: 59 additions & 70 deletions routes/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,67 @@

signUpBlueprint = Blueprint("signup", __name__)

REGISTRATION = True


@signUpBlueprint.route("/signup", methods=["GET", "POST"])
def signup():
match REGISTRATION:
match "userName" in session:
case True:
match "userName" in session:
case True:
message("1", f'USER: "{session["userName"]}" ALREADY LOGGED IN')
return redirect("/")
case False:
form = signUpForm(request.form)
if request.method == "POST":
userName = request.form["userName"]
email = request.form["email"]
password = request.form["password"]
passwordConfirm = request.form["passwordConfirm"]
userName = userName.replace(" ", "")
connection = sqlite3.connect("db/users.db")
cursor = connection.cursor()
cursor.execute("select userName from users")
users = str(cursor.fetchall())
cursor.execute("select email from users")
mails = str(cursor.fetchall())
if not userName in users and not email in mails:
if passwordConfirm == password:
match userName.isascii():
case True:
password = sha256_crypt.hash(password)
connection = sqlite3.connect("db/users.db")
cursor = connection.cursor()
cursor.execute(
f"""
insert into users(userName,email,password,profilePicture,role,points,creationDate,creationTime,isVerified)
values("{userName}","{email}","{password}",
"https://api.dicebear.com/7.x/identicon/svg?seed={userName}&radius=10",
"user",0,
"{currentDate()}",
"{currentTime()}","False")
"""
)
connection.commit()
message(
"2", f'USER: "{userName}" ADDED TO DATABASE'
)
session["userName"] = userName
addPoints(1, session["userName"])
message("2", f'USER: "{userName}" LOGGED IN')
flash(f"Welcome {userName}", "success")
return redirect("/verifyUser/codesent=false")
case False:
message(
"1",
f'USERNAME: "{userName}" DOES NOT FITS ASCII CHARACTERS',
)
flash(
"username does not fit ascii charecters",
"error",
)
elif passwordConfirm != password:
message("1", " PASSWORDS MUST MATCH ")
flash("password must match", "error")
elif userName in users and email in mails:
message("1", f'"{userName}" & "{email}" IS UNAVAILABLE ')
flash("This username and email is unavailable.", "error")
elif not userName in users and email in mails:
message("1", f'THIS EMAIL "{email}" IS UNAVAILABLE ')
flash("This email is unavailable.", "error")
elif userName in users and not email in mails:
message("1", f'THIS USERNAME "{userName}" IS UNAVAILABLE ')
flash("This username is unavailable.", "error")
return render_template("signup.html", form=form, hideSignUp=True)
message("1", f'USER: "{session["userName"]}" ALREADY LOGGED IN')
return redirect("/")
case False:
return render_template("404.html")
form = signUpForm(request.form)
if request.method == "POST":
userName = request.form["userName"]
email = request.form["email"]
password = request.form["password"]
passwordConfirm = request.form["passwordConfirm"]
userName = userName.replace(" ", "")
connection = sqlite3.connect("db/users.db")
cursor = connection.cursor()
cursor.execute("select userName from users")
users = str(cursor.fetchall())
cursor.execute("select email from users")
mails = str(cursor.fetchall())
if not userName in users and not email in mails:
if passwordConfirm == password:
match userName.isascii():
case True:
password = sha256_crypt.hash(password)
connection = sqlite3.connect("db/users.db")
cursor = connection.cursor()
cursor.execute(
f"""
insert into users(userName,email,password,profilePicture,role,points,creationDate,creationTime,isVerified)
values("{userName}","{email}","{password}",
"https://api.dicebear.com/7.x/identicon/svg?seed={userName}&radius=10",
"user",0,
"{currentDate()}",
"{currentTime()}","False")
"""
)
connection.commit()
message("2", f'USER: "{userName}" ADDED TO DATABASE')
session["userName"] = userName
addPoints(1, session["userName"])
message("2", f'USER: "{userName}" LOGGED IN')
flash(f"Welcome {userName}", "success")
return redirect("/verifyUser/codesent=false")
case False:
message(
"1",
f'USERNAME: "{userName}" DOES NOT FITS ASCII CHARACTERS',
)
flash("username does not fit ascii charecters", "error")
elif passwordConfirm != password:
message("1", " PASSWORDS MUST MATCH ")
flash("password must match", "error")
elif userName in users and email in mails:
message("1", f'"{userName}" & "{email}" IS UNAVAILABLE ')
flash("This username and email is unavailable.", "error")
elif not userName in users and email in mails:
message("1", f'THIS EMAIL "{email}" IS UNAVAILABLE ')
flash("This email is unavailable.", "error")
elif userName in users and not email in mails:
message("1", f'THIS USERNAME "{userName}" IS UNAVAILABLE ')
flash("This username is unavailable.", "error")
return render_template("signup.html", form=form, hideSignUp=True)

0 comments on commit 6996c04

Please sign in to comment.