Switch to MariaDB connector and Create UserManager Class
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import mysql.connector
|
||||
import mariadb
|
||||
|
||||
class DbManager(object):
|
||||
__connection = None
|
||||
@@ -14,6 +14,12 @@ class DbManager(object):
|
||||
return cls.__dbmanager
|
||||
|
||||
def getConnection(cls):
|
||||
if not cls.__connection:
|
||||
try:
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
|
||||
except mariadb.Error as e:
|
||||
print("Connection parameters are wrong: {e}")
|
||||
return cls.__connection
|
||||
|
||||
def __initializeConfig(cls, dbconf):
|
||||
@@ -21,6 +27,6 @@ class DbManager(object):
|
||||
'port': int (dbconf['DB_PORT']), 'host': dbconf['DB_HOST'],
|
||||
'database': dbconf['DB_NAME']
|
||||
}
|
||||
cls.__connection = mysql.connector.connect(**cls.__con_param)
|
||||
|
||||
|
||||
|
||||
|
||||
40
lib/DB/UserManager.py
Normal file
40
lib/DB/UserManager.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from .DbManager import DbManager
|
||||
from ..PyqcrmFlags import PyqcrmFlags
|
||||
|
||||
|
||||
|
||||
class UserManager():
|
||||
|
||||
def __init__(self, user_config, role):
|
||||
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
|
||||
|
||||
|
||||
def createUser(self):
|
||||
self.__cur.callproc("createUser", (self.__username, self.__password, self.__info, self.__role))
|
||||
self.__con.commit()
|
||||
self.__closeConnection()
|
||||
|
||||
def getUser(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def getUsers(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def delUser(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def updateUser(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def disableUser(self):
|
||||
self.__closeConnection()
|
||||
|
||||
def __closeConnection(self):
|
||||
self.__cur.close()
|
||||
self.__con.close()
|
||||
|
||||
Reference in New Issue
Block a user