Combiner la suppression des sessions obsolètes et la vérification de la connexion

This commit is contained in:
Valentin Moguérou 2023-05-15 06:19:11 +02:00
parent 861ae7245c
commit 2741e3ae5e
2 changed files with 1 additions and 7 deletions

View File

@ -11,12 +11,6 @@ class Database:
database=app.config["DB_DATABASE"] database=app.config["DB_DATABASE"]
) )
def delete_old_sessions(self):
cursor = self.db.cursor()
cursor.execute("DELETE FROM sessions WHERE expiry_date <= CURRENT_TIMESTAMP")
self.db.commit()
cursor.close()
def create_session(self, username, password): def create_session(self, username, password):
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("SELECT user_id FROM utilisateurs WHERE username=%s AND password=%s", (username, password)) cursor.execute("SELECT user_id FROM utilisateurs WHERE username=%s AND password=%s", (username, password))
@ -40,6 +34,7 @@ class Database:
def check_connection(self, uuid): def check_connection(self, uuid):
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("DELETE FROM sessions WHERE expiry_date <= CURRENT_TIMESTAMP")
cursor.execute("SELECT session_id FROM sessions WHERE session_id=%s", (uuid,)) cursor.execute("SELECT session_id FROM sessions WHERE session_id=%s", (uuid,))
result = cursor.fetchall() result = cursor.fetchall()
cursor.close() cursor.close()

View File

@ -8,7 +8,6 @@ from .database import Session
def views(app, db): def views(app, db):
def est_connecte(): def est_connecte():
db.delete_old_sessions()
return session.get("uuid") is not None and db.check_connection(session.get("uuid")) return session.get("uuid") is not None and db.check_connection(session.get("uuid"))
def login_required(func): def login_required(func):