bozo-backend/register.py
2023-06-09 15:22:50 +02:00

26 lines
1.1 KiB
Python

import flask
import User
import database
page = flask.Blueprint("register", __name__, template_folder="templates")
@page.route("/register", methods = ['POST', 'GET'])
def show():
if (flask.session.get("email")):
return (flask.redirect("/panel"))
if (flask.request.method == 'GET'):
return (flask.render_template("register/register.html", error = None))
email = flask.request.form.get("email");
password = flask.request.form.get("password");
first_name = flask.request.form.get("firstname");
last_name = flask.request.form.get("lastname");
username = flask.request.form.get("pseudo");
if (email == None or password == None or first_name == None or last_name == None or username == None):
return (flask.render_template("register/register.html", error = "internal error"))
user = User.User(first_name, last_name, username, password, email, {});
error = database.database.add_user(user)
if (error != None):
return (flask.render_template("register/register.html", error = error))
return (flask.redirect("/panel"))