Use ORM for applicants
This commit is contained in:
@@ -1,35 +1,28 @@
|
||||
from .DbManager import DbManager
|
||||
from PySide6.QtCore import Slot, QObject, Signal
|
||||
|
||||
from lib.domain.BaseModel import database
|
||||
from .UserDAO import UserDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags
|
||||
from ..Vermasseln import Vermasseln
|
||||
#from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput : Not working well with Nuitka
|
||||
import soundfile as sf
|
||||
import sounddevice as sd
|
||||
from .UserDAO import UserDAO
|
||||
from PySide6.QtCore import Slot, QObject, Signal, QUrl, QFile
|
||||
import tempfile
|
||||
|
||||
|
||||
|
||||
class UserManager(QObject):
|
||||
|
||||
loginOkay = Signal()
|
||||
noDbConnection = Signal(str)
|
||||
|
||||
def __init__(self, user_config = None, role = None):
|
||||
def __init__(self, user_config=None, role=None):
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__con = database.connection()
|
||||
self.__user_dao = UserDAO()
|
||||
self.__user_dao.noDbConnection.connect(self.noDbConnection)
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
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 = self.__user_dao.createUser(self.__username, self.__password, self.__info, self.__role)
|
||||
@@ -64,25 +57,6 @@ class UserManager(QObject):
|
||||
user = self.__user_dao.getUser(username)
|
||||
if user:
|
||||
self.__checkPassword(password, user[2])
|
||||
else:
|
||||
fail_src = ":/sounds/fail2c.ogg"
|
||||
with tempfile.NamedTemporaryFile(suffix='.ogg') as ogg_file:
|
||||
failure_sound = QFile(fail_src)
|
||||
if not failure_sound.open(QFile.ReadOnly):
|
||||
print(f"Failed to open resource file: {fail_src}")
|
||||
else:
|
||||
ogg_file.write(failure_sound.readAll())
|
||||
ogg_path = ogg_file.name
|
||||
fail, samplerate = sf.read(ogg_path)
|
||||
sd.play(fail, samplerate)
|
||||
|
||||
### Not working with Nuitka
|
||||
# player = QMediaPlayer(self)
|
||||
# audioOutput = QAudioOutput(self)
|
||||
# player.setAudioOutput(audioOutput)
|
||||
# player.setSource(QUrl("qrc:/sounds/fail2c.ogg"))
|
||||
# audioOutput.setVolume(150)
|
||||
# player.play()
|
||||
|
||||
def __checkPassword(self, password, hash_password):
|
||||
pw_list = hash_password.split("$")
|
||||
@@ -90,6 +64,3 @@ class UserManager(QObject):
|
||||
hash_pw = Vermasseln.userPasswordHash(password, pw_list[0])
|
||||
if hash_password == hash_pw:
|
||||
self.loginOkay.emit()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user