diff --git a/sso/services/__init__.py b/sso/services/__init__.py index 374c99f..127a8f8 100644 --- a/sso/services/__init__.py +++ b/sso/services/__init__.py @@ -63,7 +63,7 @@ class BaseService(): class BaseDBService(BaseService): @property - def _db(self): + def db(self): if not hasattr(self, '_db'): # Use the master DB settings, bar the database name backend = load_backend(settings.DATABASE_ENGINE) @@ -79,14 +79,14 @@ class BaseDBService(BaseService): return self._db @property - def _dbcursor(self): - if not hasattr(self, '__dbcursor'): - self.__dbcursor = self._db.cursor() - return self.__dbcursor + def dbcursor(self): + if not hasattr(self, '_dbcursor'): + self._dbcursor = self.db.cursor() + return self._dbcursor def __del__(self): if hasattr(self, '_db'): - self._db.connection.commit() - self._db.close() - self._db = None + self.db.connection.commit() + self.db.close() + self.db = None diff --git a/sso/services/miningbuddy/__init__.py b/sso/services/miningbuddy/__init__.py index 5369bfc..53dc92c 100644 --- a/sso/services/miningbuddy/__init__.py +++ b/sso/services/miningbuddy/__init__.py @@ -45,39 +45,39 @@ class MiningBuddyService(BaseDBService): else: email = '' - self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email]) + self.db.connection.commit() - userid = self._dbcursor.lastrowid + userid = self.dbcursor.lastrowid if 'eveapi' in kwargs: - self._dbcursor.execute(self.SQL_ADD_API, [userid, int(time.time()), kwargs['eveapi'].api_user_id, kwargs['eveapi'].api_key, kwargs['character'].id]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ADD_API, [userid, int(time.time()), kwargs['eveapi'].api_user_id, kwargs['eveapi'].api_key, kwargs['character'].id]) + self.db.connection.commit() return self._clean_username(username) def check_user(self, username): """ Check if the username exists """ - self._dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)]) - row = self._dbcursor.fetchone() + self.dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)]) + row = self.dbcursor.fetchone() if row: return True return False def delete_user(self, uid): """ Delete a user """ - self._dbcursor.execute(self.SQL_DEL_USER, [uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_DEL_USER, [uid]) + self.db.connection.commit() def disable_user(self, uid): """ Disable a user """ - self._dbcursor.execute(self.SQL_DIS_USER, [uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_DIS_USER, [uid]) + self.db.connection.commit() def enable_user(self, uid, password): """ Enable a user """ pwhash = self._gen_mb_hash(password) - self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid]) + self.db.connection.commit() return True def reset_password(self, uid, password): diff --git a/sso/services/qms/__init__.py b/sso/services/qms/__init__.py index 45b1351..b47176d 100644 --- a/sso/services/qms/__init__.py +++ b/sso/services/qms/__init__.py @@ -34,36 +34,36 @@ class QMSService(BaseDBService): """ Add a user """ email = kwargs['user'].email pwhash, salt, cert = self._gen_pwhash(password) - self._dbcursor.execute(self.SQL_ADD_USER, [username, username, pwhash, salt, email, cert]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ADD_USER, [username, username, pwhash, salt, email, cert]) + self.db.connection.commit() return username def check_user(self, username): """ Check if the username exists """ - self._dbcursor.execute(self.SQL_CHECK_USER, [username]) - row = self._dbcursor.fetchone() + self.dbcursor.execute(self.SQL_CHECK_USER, [username]) + row = self.dbcursor.fetchone() if row: return True return False def delete_user(self, uid): """ Delete a user """ - #self._dbcursor.execute(self.SQL_DEL_REV, [uid]) - #self._dbcursor.execute(self.SQL_DEL_USER, [uid]) - #self._db.connection.commit() + #self.dbcursor.execute(self.SQL_DEL_REV, [uid]) + #self.dbcursor.execute(self.SQL_DEL_USER, [uid]) + #self.db.connection.commit() return True def disable_user(self, uid): """ Disable a user """ - self._dbcursor.execute(self.SQL_DIS_USER, [uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_DIS_USER, [uid]) + self.db.connection.commit() return True def enable_user(self, uid, password): """ Enable a user """ pwhash, salt, cert = self._gen_pwhash(password) - self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, salt, cert, uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, salt, cert, uid]) + self.db.connection.commit() return True def reset_password(self, uid, password): diff --git a/sso/services/wiki/__init__.py b/sso/services/wiki/__init__.py index 42afaab..3dfd1af 100644 --- a/sso/services/wiki/__init__.py +++ b/sso/services/wiki/__init__.py @@ -49,43 +49,43 @@ class MediawikiService(BaseDBService): else: email = '' pwhash = self._gen_mw_hash(password) - self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email]) + self.db.connection.commit() return self._clean_username(username) def check_user(self, username): """ Check if the username exists """ - self._dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)]) - row = self._dbcursor.fetchone() + self.dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)]) + row = self.dbcursor.fetchone() if row: return True return False def delete_user(self, uid): """ Delete a user """ - self._dbcursor.execute(self.SQL_DEL_REV, [uid]) - self._dbcursor.execute(self.SQL_DEL_USER, [uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_DEL_REV, [uid]) + self.dbcursor.execute(self.SQL_DEL_USER, [uid]) + self.db.connection.commit() return True def disable_user(self, uid): """ Disable a user """ - #self._dbcursor.execute(self.SQL_DIS_USER, [self._gen_user_token(), uid]) + #self.dbcursor.execute(self.SQL_DIS_USER, [self._gen_user_token(), uid]) try: - self._dbcursor.execute(self.SQL_DIS_GROUP, [uid]) + self.dbcursor.execute(self.SQL_DIS_GROUP, [uid]) except IntegrityError: # Record already exists, skip it pass - self._db.connection.commit() + self.db.connection.commit() return True def enable_user(self, uid, password): """ Enable a user """ pwhash = self._gen_mw_hash(password) - self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid]) - self._db.connection.commit() - self._dbcursor.execute(self.SQL_ENABLE_GROUP, [uid]) - self._db.connection.commit() + self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid]) + self.db.connection.commit() + self.dbcursor.execute(self.SQL_ENABLE_GROUP, [uid]) + self.db.connection.commit() return True def reset_password(self, uid, password):