From aab87bb5d7d8ae14d13f5f0e04132478088404d9 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:43:06 +0200 Subject: [PATCH] add logger, move database to init prevent bug where database not reachable --- src/ui/dialogs/login.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/dialogs/login.py b/src/ui/dialogs/login.py index c51f7a7..2f2c3d1 100644 --- a/src/ui/dialogs/login.py +++ b/src/ui/dialogs/login.py @@ -7,10 +7,11 @@ from src.backend.admin_console import AdminCommands from src.backend.database import Database from .dialog_sources.Ui_login import Ui_Dialog - +from src import MyLogger class LoginDialog(Ui_Dialog): def setupUi(self, Dialog): + self.log = MyLogger("Login") Dialog.setObjectName("Dialog") Dialog.resize(218, 190) self.dialog = Dialog @@ -44,6 +45,7 @@ class LoginDialog(Ui_Dialog): self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password) self.lineEdit_2.setClearButtonEnabled(True) self.lineEdit_2.setObjectName("lineEdit_2") + self.db = Database() self.retranslateUi(Dialog) # if buttonbox accepted is clicked, launch login test @@ -64,15 +66,14 @@ class LoginDialog(Ui_Dialog): password = self.lineEdit_2.text() print(type(username), password) # Assuming 'Database' is a class to interact with your database - db = Database() hashed_password = hashlib.sha256(password.encode()).hexdigest() - if len(db.getUsers()) == 0: + if len(self.db.getUsers()) == 0: AdminCommands().create_admin() self.lresult = 1 # Indicate successful login self.lusername = username self.dialog.accept() - if db.login(username, hashed_password): + if self.db.login(username, hashed_password): self.lresult = 1 # Indicate successful login self.lusername = username self.dialog.accept()