add: login feature
This commit is contained in:
parent
5dd09fcc1c
commit
1381bc2d0b
14
Database.py
14
Database.py
@ -59,9 +59,6 @@ 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.execute(f"SELECT * FROM `users` WHERE `email` = '{user.email}'")
|
|
||||||
if (len(self.cursor.fetchall())):
|
|
||||||
return ("Email already used")
|
|
||||||
if (len(user.password) < 8):
|
if (len(user.password) < 8):
|
||||||
return ("Password too short (minimum 8 chars)")
|
return ("Password too short (minimum 8 chars)")
|
||||||
if (len(user.first_name) == 0):
|
if (len(user.first_name) == 0):
|
||||||
@ -70,6 +67,17 @@ class Database:
|
|||||||
return ("Last name empty")
|
return ("Last name empty")
|
||||||
if (len(user.username) == 0):
|
if (len(user.username) == 0):
|
||||||
return ("Username empty")
|
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.cursor.execute(user.to_insert_sql())
|
||||||
self.mydb.commit()
|
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);
|
||||||
|
12
login.py
12
login.py
@ -1,12 +1,14 @@
|
|||||||
import flask
|
import flask
|
||||||
|
import database
|
||||||
|
|
||||||
page = flask.Blueprint("login", __name__, template_folder="templates")
|
page = flask.Blueprint("login", __name__, template_folder="templates")
|
||||||
|
|
||||||
@page.route("/login", methods=['POST', 'GET'])
|
@page.route("/login", methods=['POST', 'GET'])
|
||||||
def show():
|
def show():
|
||||||
if (flask.request.method == ['GET']):
|
if (flask.request.method == 'GET'):
|
||||||
return (flask.render_template("login/login.html"))
|
return (flask.render_template("login/login.html"))
|
||||||
else:
|
email = flask.request.form['email']
|
||||||
return ("bozo")
|
password = flask.request.form['password']
|
||||||
email = flask.request.form['email']
|
if (database.database.account_test(email, password)):
|
||||||
password = flask.request.form['password']
|
return (flask.render_template("login/login.html", error = "Invalid credentials"))
|
||||||
|
return (flask.redirect("/panel"))
|
||||||
|
Loading…
Reference in New Issue
Block a user