bozo-backend/register.py

26 lines
1.1 KiB
Python
Raw Permalink Normal View History

import flask
2023-06-08 10:32:44 -04:00
import User
import database
page = flask.Blueprint("register", __name__, template_folder="templates")
2023-06-08 10:32:44 -04:00
@page.route("/register", methods = ['POST', 'GET'])
def show():
2023-06-09 09:22:50 -04:00
if (flask.session.get("email")):
return (flask.redirect("/panel"))
2023-06-08 10:32:44 -04:00
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"))