add: register feature
This commit is contained in:
parent
514f037968
commit
5dd09fcc1c
14
Database.py
14
Database.py
@ -59,5 +59,17 @@ class Database:
|
|||||||
self._create_table("users", data)
|
self._create_table("users", data)
|
||||||
|
|
||||||
def add_user(self, user: User):
|
def add_user(self, user: User):
|
||||||
self.cursor(user.to_insert_sql())
|
self.cursor.execute(f"SELECT * FROM `users` WHERE `email` = '{user.email}'")
|
||||||
|
if (len(self.cursor.fetchall())):
|
||||||
|
return ("Email already used")
|
||||||
|
if (len(user.password) < 8):
|
||||||
|
return ("Password too short (minimum 8 chars)")
|
||||||
|
if (len(user.first_name) == 0):
|
||||||
|
return ("First name empty")
|
||||||
|
if (len(user.last_name) == 0):
|
||||||
|
return ("Last name empty")
|
||||||
|
if (len(user.username) == 0):
|
||||||
|
return ("Username empty")
|
||||||
|
self.cursor.execute(user.to_insert_sql())
|
||||||
|
self.mydb.commit()
|
||||||
|
|
||||||
|
3
User.py
3
User.py
@ -14,6 +14,7 @@ class User:
|
|||||||
"""
|
"""
|
||||||
self.first_name: str = first_name;
|
self.first_name: str = first_name;
|
||||||
self.last_name: str = last_name;
|
self.last_name: str = last_name;
|
||||||
|
self.email: str = email
|
||||||
self.username: str = username;
|
self.username: str = username;
|
||||||
self.password: str = password;
|
self.password: str = password;
|
||||||
self.permission = permissions;
|
self.permission = permissions;
|
||||||
@ -22,4 +23,4 @@ class User:
|
|||||||
"""
|
"""
|
||||||
return text to add the user in the database
|
return text to add the user in the database
|
||||||
"""
|
"""
|
||||||
return (f"INSERT INTO users (email, username, first_name, last_name, password) VALUES ({self.email}, {self.username}, {self.first_name}, {self.last_name}, {self.password})")
|
return (f"INSERT INTO users (email, username, first_name, last_name, password) VALUES ('{self.email}', '{self.username}', '{self.first_name}', '{self.last_name}', '{self.password}')")
|
||||||
|
20
register.py
20
register.py
@ -1,7 +1,23 @@
|
|||||||
import flask
|
import flask
|
||||||
|
import User
|
||||||
|
import database
|
||||||
|
|
||||||
page = flask.Blueprint("register", __name__, template_folder="templates")
|
page = flask.Blueprint("register", __name__, template_folder="templates")
|
||||||
|
|
||||||
@page.route("/register")
|
@page.route("/register", methods = ['POST', 'GET'])
|
||||||
def show():
|
def show():
|
||||||
return (flask.render_template("register/register.html"))
|
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"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user