FirstStart angepasst
This commit is contained in:
@@ -6,6 +6,7 @@ from PySide6.QtCore import QObject, Slot
|
||||
from .Vermasseln import Vermasseln
|
||||
import shutil
|
||||
from urllib.parse import urlparse
|
||||
from .DB.DbManager import DbManager
|
||||
import os
|
||||
|
||||
class ConfigLoader(QObject):
|
||||
@@ -31,31 +32,57 @@ class ConfigLoader(QObject):
|
||||
confile = confile[1:]
|
||||
shutil.copyfile(confile, self.config_dir+ '/pyqcrm.toml')
|
||||
|
||||
@Slot(dict)
|
||||
@Slot(dict, result= bool)
|
||||
def addAdminUser(self, admin_config):
|
||||
print(admin_config)
|
||||
return True
|
||||
|
||||
@Slot(dict, result= bool)
|
||||
def setConfig(self, app_config):
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'w') as f:
|
||||
config = Vermasseln().oscarVermasseln(toml.dumps(app_config))
|
||||
f.write(config)
|
||||
except FileNotFoundError:
|
||||
print("Konnte die Konfiguration nicht speichern.")
|
||||
|
||||
conf = self.__checkDbConnection(app_config)
|
||||
if conf:
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'w') as f:
|
||||
config = Vermasseln().oscarVermasseln(toml.dumps(app_config))
|
||||
f.write(config)
|
||||
except FileNotFoundError:
|
||||
conf = False
|
||||
print("Konnte die Konfiguration nicht speichern.")
|
||||
conf = self.__checkAdminUser()
|
||||
|
||||
return conf
|
||||
|
||||
|
||||
def __configLoad(self):
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'r') as f:
|
||||
config = f.read()
|
||||
|
||||
self.__config = toml.loads(Vermasseln().entschluesseln(config))
|
||||
except FileNotFoundError:
|
||||
print("Konnte die Konfiguration nicht laden.")
|
||||
|
||||
except TypeError:
|
||||
print("Invalid Configuration")
|
||||
# except Exception as e:
|
||||
# print(str(e))
|
||||
|
||||
|
||||
def getConfig(self):
|
||||
|
||||
return self.__config
|
||||
|
||||
def createConfig(self):
|
||||
def __createConfig(self):
|
||||
|
||||
with open(self.config_dir + '/pyqcrm.toml', "w") as datei:
|
||||
datei.write("[pyqcrm]")
|
||||
|
||||
def __checkDbConnection(self, db_config):
|
||||
con = DbManager(db_config['database']).getConnection()
|
||||
if con:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def __checkAdminUser(self):
|
||||
pass
|
||||
|
||||
13
lib/Test.py
Normal file
13
lib/Test.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import toml
|
||||
|
||||
|
||||
class Singleton(object):
|
||||
def __new__(cls):
|
||||
if not hasattr(cls, "__instance"):
|
||||
cls.__instance = super().__new__(cls)
|
||||
return cls.__instance
|
||||
|
||||
class DbManager(Singleton):
|
||||
def __init__(self, dbconf):
|
||||
toml.
|
||||
|
||||
@@ -17,11 +17,19 @@ class Vermasseln:
|
||||
return storable_data
|
||||
|
||||
def entschluesseln(self, data):
|
||||
data_list = data.split(".")
|
||||
encoded_data = [b64decode(x) for x in data_list]
|
||||
cipher = self.__vermasslungsKobold()
|
||||
decrypted_data = cipher.decrypt_and_verify(encoded_data[0], encoded_data[1])
|
||||
decrypted_data = decrypted_data.decode("utf-8")
|
||||
try:
|
||||
data_list = data.split(".")
|
||||
encoded_data = [b64decode(x) for x in data_list]
|
||||
cipher = self.__vermasslungsKobold()
|
||||
decrypted_data = cipher.decrypt_and_verify(encoded_data[0], encoded_data[1])
|
||||
decrypted_data = decrypted_data.decode("utf-8")
|
||||
except (ValueError, IndexError):
|
||||
print("Configuration corrupted")
|
||||
decrypted_data = None
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
decrypted_data = None
|
||||
|
||||
return decrypted_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user