add: login feature

This commit is contained in:
starnakin 2023-06-08 22:32:56 +02:00
parent 5dd09fcc1c
commit 1381bc2d0b
3 changed files with 18 additions and 15 deletions

View File

@ -59,9 +59,6 @@ class Database:
self._create_table("users", data)
def add_user(self, user: User):
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):
@ -70,6 +67,17 @@ class Database:
return ("Last name empty")
if (len(user.username) == 0):
return ("Username empty")
self.cursor.execute(f"SELECT * FROM `users` WHERE `email` = '{user.email}'")
if (len(self.cursor.fetchall())):
return ("Email already used")
self.cursor.execute(user.to_insert_sql())
self.mydb.commit()
def account_test(self, email: str, password: str):
self.cursor.execute(f"SELECT * FROM `users` WHERE `email` = '{email}'")
result = self.cursor.fetchall()
if (len(result) == 0):
return (1);
if (result[0][-1] != password):
return (1);
return (0);

View File

@ -1,12 +1,14 @@
import flask
import database
page = flask.Blueprint("login", __name__, template_folder="templates")
@page.route("/login", methods=['POST', 'GET'])
def show():
if (flask.request.method == ['GET']):
if (flask.request.method == 'GET'):
return (flask.render_template("login/login.html"))
else:
return ("bozo")
email = flask.request.form['email']
password = flask.request.form['password']
email = flask.request.form['email']
password = flask.request.form['password']
if (database.database.account_test(email, password)):
return (flask.render_template("login/login.html", error = "Invalid credentials"))
return (flask.redirect("/panel"))

View File

@ -1,7 +0,0 @@
import flask
page = flask.Blueprint("panel", __name__, template_folder="templates")
@page.route("/")
def show():
return (flask.render_template("panel/panel.html"))