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 .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()
|
||||
|
||||
Reference in New Issue
Block a user