mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-17 19:59:29 +00:00
Added a better disable function, now uses a Mediawiki group to destroy all access even if they can login
This commit is contained in:
@@ -15,8 +15,10 @@ class MediawikiService(BaseService):
|
|||||||
'provide_login': False }
|
'provide_login': False }
|
||||||
|
|
||||||
SQL_ADD_USER = r"INSERT INTO user (user_name, user_password, user_newpassword, user_email) VALUES (%s, %s, '', %s)"
|
SQL_ADD_USER = r"INSERT INTO user (user_name, user_password, user_newpassword, user_email) VALUES (%s, %s, '', %s)"
|
||||||
SQL_DIS_USER = r"UPDATE user SET user_password = '', user_email = '' WHERE user_name = %s"
|
SQL_DIS_USER = r"UPDATE user SET user_password = '', user_email = '', user_token = %s WHERE user_name = %s"
|
||||||
|
SQL_DIS_GROUP = r"INSERT INTO user_groups (ug_user, ug_group) VALUES ((SELECT user_id FROM user WHERE user_name = %s), 'Disabled')"
|
||||||
SQL_ENABLE_USER = r"UPDATE user SET user_password = %s WHERE user_name = %s"
|
SQL_ENABLE_USER = r"UPDATE user SET user_password = %s WHERE user_name = %s"
|
||||||
|
SQL_ENABLE_GROUP = r"DELETE FROM user_groups where ug_user = (SELECT user_id FROM user WHERE user_name = %s) AND ug_group = 'Disabled'"
|
||||||
SQL_CHECK_USER = r"SELECT user_name from user WHERE user_name = %s"
|
SQL_CHECK_USER = r"SELECT user_name from user WHERE user_name = %s"
|
||||||
|
|
||||||
SQL_DEL_REV = r"UPDATE revision SET rev_user = (SELECT user_id FROM user WHERE user_name = 'DeletedUser'), rev_user_text = 'DeletedUser' WHERE rev_user = (SELECT user_id FROM user WHERE user_name = %s)"
|
SQL_DEL_REV = r"UPDATE revision SET rev_user = (SELECT user_id FROM user WHERE user_name = 'DeletedUser'), rev_user_text = 'DeletedUser' WHERE rev_user = (SELECT user_id FROM user WHERE user_name = %s)"
|
||||||
@@ -50,6 +52,10 @@ class MediawikiService(BaseService):
|
|||||||
hash = hashlib.md5('%s-%s' % (salt, hashlib.md5(password).hexdigest())).hexdigest()
|
hash = hashlib.md5('%s-%s' % (salt, hashlib.md5(password).hexdigest())).hexdigest()
|
||||||
return ":B:%s:%s" % (salt, hash)
|
return ":B:%s:%s" % (salt, hash)
|
||||||
|
|
||||||
|
def _gen_user_token(self):
|
||||||
|
hash = hashlib.md5(self._gen_salt()).hexdigest()
|
||||||
|
return hash
|
||||||
|
|
||||||
def _clean_username(self, username):
|
def _clean_username(self, username):
|
||||||
username = username.strip()
|
username = username.strip()
|
||||||
return username[0].upper() + username[1:]
|
return username[0].upper() + username[1:]
|
||||||
@@ -82,7 +88,8 @@ class MediawikiService(BaseService):
|
|||||||
|
|
||||||
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, [self._gen_user_token(), uid])
|
||||||
|
self._dbcursor.execute(self.SQL_DIS_GROUP, [uid])
|
||||||
self._db.connection.commit()
|
self._db.connection.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -91,6 +98,8 @@ class MediawikiService(BaseService):
|
|||||||
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_ENABBLE_GROUP, [uid])
|
||||||
|
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