add logger, move database to init
prevent bug where database not reachable
This commit is contained in:
@@ -7,10 +7,11 @@ from src.backend.admin_console import AdminCommands
|
|||||||
from src.backend.database import Database
|
from src.backend.database import Database
|
||||||
|
|
||||||
from .dialog_sources.Ui_login import Ui_Dialog
|
from .dialog_sources.Ui_login import Ui_Dialog
|
||||||
|
from src import MyLogger
|
||||||
|
|
||||||
class LoginDialog(Ui_Dialog):
|
class LoginDialog(Ui_Dialog):
|
||||||
def setupUi(self, Dialog):
|
def setupUi(self, Dialog):
|
||||||
|
self.log = MyLogger("Login")
|
||||||
Dialog.setObjectName("Dialog")
|
Dialog.setObjectName("Dialog")
|
||||||
Dialog.resize(218, 190)
|
Dialog.resize(218, 190)
|
||||||
self.dialog = Dialog
|
self.dialog = Dialog
|
||||||
@@ -44,6 +45,7 @@ class LoginDialog(Ui_Dialog):
|
|||||||
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
|
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
|
||||||
self.lineEdit_2.setClearButtonEnabled(True)
|
self.lineEdit_2.setClearButtonEnabled(True)
|
||||||
self.lineEdit_2.setObjectName("lineEdit_2")
|
self.lineEdit_2.setObjectName("lineEdit_2")
|
||||||
|
self.db = Database()
|
||||||
|
|
||||||
self.retranslateUi(Dialog)
|
self.retranslateUi(Dialog)
|
||||||
# if buttonbox accepted is clicked, launch login test
|
# if buttonbox accepted is clicked, launch login test
|
||||||
@@ -64,15 +66,14 @@ class LoginDialog(Ui_Dialog):
|
|||||||
password = self.lineEdit_2.text()
|
password = self.lineEdit_2.text()
|
||||||
print(type(username), password)
|
print(type(username), password)
|
||||||
# Assuming 'Database' is a class to interact with your database
|
# Assuming 'Database' is a class to interact with your database
|
||||||
db = Database()
|
|
||||||
|
|
||||||
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
||||||
if len(db.getUsers()) == 0:
|
if len(self.db.getUsers()) == 0:
|
||||||
AdminCommands().create_admin()
|
AdminCommands().create_admin()
|
||||||
self.lresult = 1 # Indicate successful login
|
self.lresult = 1 # Indicate successful login
|
||||||
self.lusername = username
|
self.lusername = username
|
||||||
self.dialog.accept()
|
self.dialog.accept()
|
||||||
if db.login(username, hashed_password):
|
if self.db.login(username, hashed_password):
|
||||||
self.lresult = 1 # Indicate successful login
|
self.lresult = 1 # Indicate successful login
|
||||||
self.lusername = username
|
self.lusername = username
|
||||||
self.dialog.accept()
|
self.dialog.accept()
|
||||||
|
|||||||
Reference in New Issue
Block a user