Einloggen funktioniert
This commit is contained in:
@@ -2,38 +2,35 @@ from .DbManager import DbManager
|
||||
from ..PyqcrmFlags import PyqcrmFlags
|
||||
from ..Vermasseln import Vermasseln
|
||||
import mariadb
|
||||
from .UserDAO import UserDAO
|
||||
from PySide6.QtCore import Slot, QObject, Signal
|
||||
|
||||
|
||||
|
||||
class UserManager():
|
||||
class UserManager(QObject):
|
||||
|
||||
def __init__(self, user_config, role):
|
||||
loginOkay = Signal()
|
||||
|
||||
def __init__(self, user_config = None, role = None):
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
self.__username = user_config["PYQCRM_USER"]
|
||||
self.__password = user_config["PYQCRM_USER_PASS"]
|
||||
self.__info = user_config["PYQCRM_USER_INFO"]
|
||||
self.__role = role if role == PyqcrmFlags.ADMIN else 0
|
||||
if user_config and role:
|
||||
|
||||
self.__username = user_config["PYQCRM_USER"]
|
||||
self.__password = user_config["PYQCRM_USER_PASS"]
|
||||
self.__info = user_config["PYQCRM_USER_INFO"]
|
||||
self.__role = role if role == PyqcrmFlags.ADMIN else 0
|
||||
|
||||
|
||||
def createUser(self):
|
||||
self.__hashPassword()
|
||||
user_created = True
|
||||
try:
|
||||
self.__cur.callproc("createUser", (self.__username, self.__password, self.__info, self.__role))
|
||||
self.__con.commit()
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
print(e.errno)
|
||||
user_created = False
|
||||
finally:
|
||||
self.__cur.close()
|
||||
#self.__closeConnection()
|
||||
return user_created
|
||||
user_created = UserDAO().createUser(self.__username, self.__password, self.__info, self.__role)
|
||||
|
||||
return user_created
|
||||
|
||||
def __hashPassword(self):
|
||||
self.__password = Vermasseln.userPasswordHash(self.__password)
|
||||
print (self.__password)
|
||||
|
||||
|
||||
def getUser(self):
|
||||
@@ -51,7 +48,16 @@ class UserManager():
|
||||
def disableUser(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def __closeConnection(self):
|
||||
self.__cur.close()
|
||||
self.__con.close()
|
||||
@Slot(str, str)
|
||||
def login(self, username, password):
|
||||
user = UserDAO().getUser(username)
|
||||
if user:
|
||||
self.__checkPassword(password, user[2])
|
||||
|
||||
def __checkPassword(self, password, hash_password):
|
||||
pwList = hash_password.split("$")
|
||||
|
||||
hash_Pw = Vermasseln.userPasswordHash(password, pwList[0])
|
||||
if hash_password == hash_Pw:
|
||||
self.loginOkay.emit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user