mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-17 19:59:29 +00:00
Fixes all db service issues
This commit is contained in:
@@ -63,7 +63,7 @@ class BaseService():
|
|||||||
class BaseDBService(BaseService):
|
class BaseDBService(BaseService):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _db(self):
|
def db(self):
|
||||||
if not hasattr(self, '_db'):
|
if not hasattr(self, '_db'):
|
||||||
# Use the master DB settings, bar the database name
|
# Use the master DB settings, bar the database name
|
||||||
backend = load_backend(settings.DATABASE_ENGINE)
|
backend = load_backend(settings.DATABASE_ENGINE)
|
||||||
@@ -79,14 +79,14 @@ class BaseDBService(BaseService):
|
|||||||
return self._db
|
return self._db
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _dbcursor(self):
|
def dbcursor(self):
|
||||||
if not hasattr(self, '__dbcursor'):
|
if not hasattr(self, '_dbcursor'):
|
||||||
self.__dbcursor = self._db.cursor()
|
self._dbcursor = self.db.cursor()
|
||||||
return self.__dbcursor
|
return self._dbcursor
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if hasattr(self, '_db'):
|
if hasattr(self, '_db'):
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
self._db.close()
|
self.db.close()
|
||||||
self._db = None
|
self.db = None
|
||||||
|
|
||||||
|
|||||||
@@ -45,39 +45,39 @@ class MiningBuddyService(BaseDBService):
|
|||||||
else:
|
else:
|
||||||
email = ''
|
email = ''
|
||||||
|
|
||||||
self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
|
|
||||||
userid = self._dbcursor.lastrowid
|
userid = self.dbcursor.lastrowid
|
||||||
if 'eveapi' in kwargs:
|
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.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.db.connection.commit()
|
||||||
|
|
||||||
return self._clean_username(username)
|
return self._clean_username(username)
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
""" Check if the username exists """
|
""" Check if the username exists """
|
||||||
self._dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)])
|
self.dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)])
|
||||||
row = self._dbcursor.fetchone()
|
row = self.dbcursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def delete_user(self, uid):
|
def delete_user(self, uid):
|
||||||
""" Delete a user """
|
""" Delete a user """
|
||||||
self._dbcursor.execute(self.SQL_DEL_USER, [uid])
|
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
|
|
||||||
def disable_user(self, uid):
|
def disable_user(self, uid):
|
||||||
""" Disable a user """
|
""" Disable a user """
|
||||||
self._dbcursor.execute(self.SQL_DIS_USER, [uid])
|
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
|
|
||||||
def enable_user(self, uid, password):
|
def enable_user(self, uid, password):
|
||||||
""" Enable a user """
|
""" Enable a user """
|
||||||
pwhash = self._gen_mb_hash(password)
|
pwhash = self._gen_mb_hash(password)
|
||||||
self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -34,36 +34,36 @@ class QMSService(BaseDBService):
|
|||||||
""" Add a user """
|
""" Add a user """
|
||||||
email = kwargs['user'].email
|
email = kwargs['user'].email
|
||||||
pwhash, salt, cert = self._gen_pwhash(password)
|
pwhash, salt, cert = self._gen_pwhash(password)
|
||||||
self._dbcursor.execute(self.SQL_ADD_USER, [username, username, pwhash, salt, email, cert])
|
self.dbcursor.execute(self.SQL_ADD_USER, [username, username, pwhash, salt, email, cert])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return username
|
return username
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
""" Check if the username exists """
|
""" Check if the username exists """
|
||||||
self._dbcursor.execute(self.SQL_CHECK_USER, [username])
|
self.dbcursor.execute(self.SQL_CHECK_USER, [username])
|
||||||
row = self._dbcursor.fetchone()
|
row = self.dbcursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def delete_user(self, uid):
|
def delete_user(self, uid):
|
||||||
""" Delete a user """
|
""" Delete a user """
|
||||||
#self._dbcursor.execute(self.SQL_DEL_REV, [uid])
|
#self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||||
#self._dbcursor.execute(self.SQL_DEL_USER, [uid])
|
#self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||||
#self._db.connection.commit()
|
#self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disable_user(self, uid):
|
def disable_user(self, uid):
|
||||||
""" Disable a user """
|
""" Disable a user """
|
||||||
self._dbcursor.execute(self.SQL_DIS_USER, [uid])
|
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def enable_user(self, uid, password):
|
def enable_user(self, uid, password):
|
||||||
""" Enable a user """
|
""" Enable a user """
|
||||||
pwhash, salt, cert = self._gen_pwhash(password)
|
pwhash, salt, cert = self._gen_pwhash(password)
|
||||||
self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, salt, cert, uid])
|
self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, salt, cert, uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -49,43 +49,43 @@ class MediawikiService(BaseDBService):
|
|||||||
else:
|
else:
|
||||||
email = ''
|
email = ''
|
||||||
pwhash = self._gen_mw_hash(password)
|
pwhash = self._gen_mw_hash(password)
|
||||||
self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return self._clean_username(username)
|
return self._clean_username(username)
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
""" Check if the username exists """
|
""" Check if the username exists """
|
||||||
self._dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)])
|
self.dbcursor.execute(self.SQL_CHECK_USER, [self._clean_username(username)])
|
||||||
row = self._dbcursor.fetchone()
|
row = self.dbcursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def delete_user(self, uid):
|
def delete_user(self, uid):
|
||||||
""" Delete a user """
|
""" Delete a user """
|
||||||
self._dbcursor.execute(self.SQL_DEL_REV, [uid])
|
self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||||
self._dbcursor.execute(self.SQL_DEL_USER, [uid])
|
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disable_user(self, uid):
|
def disable_user(self, uid):
|
||||||
""" Disable a user """
|
""" 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:
|
try:
|
||||||
self._dbcursor.execute(self.SQL_DIS_GROUP, [uid])
|
self.dbcursor.execute(self.SQL_DIS_GROUP, [uid])
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# Record already exists, skip it
|
# Record already exists, skip it
|
||||||
pass
|
pass
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def enable_user(self, uid, password):
|
def enable_user(self, uid, password):
|
||||||
""" Enable a user """
|
""" Enable a user """
|
||||||
pwhash = self._gen_mw_hash(password)
|
pwhash = self._gen_mw_hash(password)
|
||||||
self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
self._dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
self.dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
||||||
self._db.connection.commit()
|
self.db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
Reference in New Issue
Block a user