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)
|
||||
|
||||
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);
|
||||
|
12
login.py
12
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"))
|
||||
|
Loading…
Reference in New Issue
Block a user