diff --git a/Database.py b/Database.py index 806f9cb..f169cf3 100644 --- a/Database.py +++ b/Database.py @@ -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); diff --git a/login.py b/login.py index da7aa9d..2ee957c 100644 --- a/login.py +++ b/login.py @@ -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")) diff --git a/panel.py b/panel.py deleted file mode 100644 index 0f853f5..0000000 --- a/panel.py +++ /dev/null @@ -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"))