def create_additional_users(self, params=None): try: resp = None DATABASE = params.get("client_name").upper() username = params.get("client_username") client = erppeek.Client(server = self.portal_url) if DATABASE in client.db.list(): self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, DATABASE) self.connect = self.connection.connect_postgreSQL() result = self.connection.getRecords(self.connect, DATABASE, "res_users") if result is not None: for rows in result: if rows[0] == username: resp = {'auth-result': 'Complete'} break else: resp = {'auth-result': 'Invalid User'} else: logging.warning("[WARNING] USER RESULT NOT FOUND IN ODOO") else: resp = {'auth-result':'Invalid User'} except Exception as er: logging.warning("[WARNING] CREATE ADDTIONAL USERS EXCEPTION :: %s"%er) return resp
def additional_users(self, params): try: resp = None database = params.get("client_name").upper() client_username = params.get("client_subusername") client_name = params.get("client_subusername") client_password = params.get("client_password") common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format( self.portal_url)) uid = common.authenticate(database, 'admin', self.dbpwd, {}) models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format( self.portal_url)) self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, database) self.connect = self.connection.connect_postgreSQL() user_id = models.execute_kw(database, uid, self.dbpwd, 'res.users', 'create', [{ 'name': client_username, 'login': client_name, 'company_ids': [1], 'company_id': 1, 'new_password': client_password, }]) update_pwd = self.connection.reset_admin_pwd(self.connect, user_id) resp = {"auth-result": "CREATED ID %s" % user_id} except Exception as er: resp = {"auth-result": "USERNAME ALREADY EXIST"} logging.warning( "[WARNING] CREATE ADDITIONAL NEW USER EXCEPTION :: %s" % er) return resp
def get_newDatabase_admin_id(self, database): try: user_id = None self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, database) self.connect = self.connection.connect_postgreSQL() self.connLink = self.connect.cursor() self.connLink.execute( "SELECT * FROM res_users WHERE login='******'") rows = self.connLink.fetchall() for row in rows: user_id = row[0] print("\n [SUCCESS] CURRENT DATABASE NAME : " + database + " & ADMIN USER ID :: %s" % user_id) if user_id is None: print( "\n [WARNING] ADMIN USER NAME NOT FOUND IN CURRENT DATABASE " + database + " TRY AFTER SOMETIME") else: self.connection.reset_admin_pwd(self.connect, user_id) self.create_admin_subUsers(database, self.params) except Exception as er: print("\n [WARNING] CREATED NEW DATABASE " + database + "FUNCTION EXCEPTION :: %s" % er) return user_id
def connect_user_database(self, dbName): try: self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, dbName) self.connect = self.connection.connect_postgreSQL() except Exception as er: logging.warning("[WARNING] I AM UNABLE TO CONNECT TO THE POSTGRESQL DATABASE FUNCTION EXCEPTION :: %s"%er) return self.connection
def create_usrInfoTable(self, params): try: DATABASE = params.get("databaseName").upper() self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, self.dbName) self.connect = self.connection.connect_postgreSQL() #self.connection.create_table(self.connect) self.connection.insertUsrRecords(self.connect, params) except Exception as er: logging.warning("[WARNING] CREATE USER INFORMATIONSAVED COLLECTION EXCEPTION :: %s"%er)
def create_usr_info_table(self): try: database = "TERAFASTWORKS" self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, database) self.connect = self.connection.connect_postgreSQL() # self.connection.create_table(self.connect) self.connection.insert_user_info(self.connect, self.param) except Exception as er: print("\n [WARNING] CREATE USERS BASIC INFO TABLE EXCEPTION :: %s"%er)
def masterDbConn(): try: conn = None postgreConn = postgreLib.postgreLib(dbIp, dbPort, dbUser_name, db_pwd, database_name) conn = postgreConn.connect_postgreSQL() except Exception as er: print"[WARNING] CONNECT MASTER DATABASE FUNCTION EXCEPTION :: %s"%er return conn
def updateUserLimitCount(self, params): try: numCount = None; numCount = self.getUserLimitValidation(params) lastCount = numCount[0][1] latestUpdate = lastCount + 1 connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, self.dbName) connect = connection.connect_postgreSQL() update = connection.usrInfoNumberCount(connect, params, latestUpdate) except Exception as er: logging.warning("[WARNING] UPDATE USER LIMIT COUNT EXCEPTION :: %s"%er)
def getUserLimitValidation(self, params): try: userList = None connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, self.dbName) connect = connection.connect_postgreSQL() userList = connection.getUserLimit(connect, params) except Exception as er: logging.warning("[WARNING] ADDONUSERS LIMIT EXCEPTION :: %s"%er) return userList
def userLogin(self, params): try: resp = None connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, self.dbName) connect = connection.connect_postgreSQL() dbName = connection.userLogin(connect, params) if dbName is not None: resp = dbName[0] else: resp = "username or password mismatch" except Exception as er: logging.warning("[WARNING] USERS LOGIN EXCEPTION :: %s"%er) return resp
def additional_users(self, params): try: resp = None database = params.get("client_name").upper() client_username = params.get("client_subusername") client_name = params.get("client_subusername") client_password = params.get("client_password") selec_lang = params.get("language") print "*******************************************************************" common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.portal_url)) uid = common.authenticate(database, 'admin', self.dbpwd, {}) models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(self.portal_url)) userLimitDet = self.getUserLimitValidation(database) accessLimit = userLimitDet[0][0] countUser = userLimitDet[0][1] if accessLimit > countUser: self.connection = postgreLib.postgreLib(self.dbIp, self.dbPort, self.dbusername, self.dbpwd, database) self.connect = self.connection.connect_postgreSQL() user_id = models.execute_kw(database, uid, self.dbpwd, 'res.users', 'create', [{ 'name': client_username, 'login':client_name, 'company_ids':[1], 'company_id':1, 'new_password': client_password, 'lang' : selec_lang }]) update_pwd = self.connection.reset_admin_pwd(self.connect, user_id, client_password)#'b2kstorage') self.updateUserLimitCount(database) resp = {"auth-result" : "CREATED ID %s"%user_id} else: resp = {"auth-result" : "Maximum number of user's limit exceeded please upgrade your plan"} except Exception as er: resp = {"auth-result":"USERNAME ALREADY EXIST"} logging.warning("[WARNING] CREATE ADDITIONAL NEW USER EXCEPTION :: %s"%er) return resp
dbIp = config['postgreSql']['ip'] dbPort = int(config['postgreSql']['port']) dbUser_name = config['postgreSql']['username'] db_pwd = config['postgreSql']['pwd'] database_name = config['database']['dbname'] portal_port = int(config['portal']['poratal_port']) portal_admin_name = config['portal']['admin_username'] MerchantId = config["payload"]["MerchantId"] MerchantKey = config["payload"]["MerchantKey"] url = config["payload"]["url"] odoo_libConn = odoofactory.odooLibrary(dbIp, dbPort, dbUser_name, db_pwd, database_name, portal_port, portal_admin_name) payload_cont = make_payment.make_payment(MerchantId, MerchantKey, url) postgreConn = postgreLib.postgreLib(dbIp, dbPort, dbUser_name, db_pwd, database_name) #conn = postgreConn.connect_postgreSQL() #info_coll = postgreConn.create_table(conn) #collection = postgreConn.create_paymentTable(conn) @app.route('/') def hello_world(): return jsonify({"version":1.0}) def masterDbConn(): try: conn = None postgreConn = postgreLib.postgreLib(dbIp, dbPort, dbUser_name, db_pwd, database_name) conn = postgreConn.connect_postgreSQL() except Exception as er: