mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Various fixes to SSO services, including transaction handling and correct DbService handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import settings
|
||||
from django.db import load_backend, transaction, IntegrityError
|
||||
from django.db import load_backend, transaction, IntegrityError, connections
|
||||
|
||||
def get_api(api):
|
||||
|
||||
|
||||
@@ -46,12 +46,10 @@ class MiningBuddyService(BaseDBService):
|
||||
email = ''
|
||||
|
||||
self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
||||
transaction.set_dirty()
|
||||
|
||||
userid = self.dbcursor.lastrowid
|
||||
api = kwargs['character'].eveaccount_set.all()[0]
|
||||
self.dbcursor.execute(self.SQL_ADD_API, [userid, int(time.time()), api.api_user_id, api.api_key, kwargs['character'].id])
|
||||
transaction.set_dirty()
|
||||
|
||||
return { 'username': self._clean_username(username), 'password': password }
|
||||
|
||||
@@ -66,20 +64,17 @@ class MiningBuddyService(BaseDBService):
|
||||
def delete_user(self, uid):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
""" Enable a user """
|
||||
pwhash = self._gen_mb_hash(password)
|
||||
self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -41,7 +41,6 @@ class PhpBBService(BaseDBService):
|
||||
pwhash = self._gen_hash(password)
|
||||
|
||||
self._dbcursor.execute(self.SQL_ADD_USER, [username, pwhash, email])
|
||||
transaction.set_dirty()
|
||||
|
||||
self.update_groups(username)
|
||||
return { 'username': username, 'password': password }
|
||||
@@ -56,12 +55,10 @@ class PhpBBService(BaseDBService):
|
||||
row = self._dbcursor.fetchone()
|
||||
if not row:
|
||||
self._dbcursor.execute(self.SQL_ADD_GROUP, [group.name])
|
||||
transaction.set_dirty()
|
||||
self._dbcursor.execute(self.SQL_GET_GROUP, [group.name])
|
||||
row = self._dbcursor.fetchone()
|
||||
|
||||
self._dbcursor.execute(self.SQL_ADD_USER_GROUP, [row['group_id'], user_id])
|
||||
transaction.set_dirty()
|
||||
|
||||
def check_user(self, username):
|
||||
""" Check if the username exists """
|
||||
@@ -83,7 +80,6 @@ class PhpBBService(BaseDBService):
|
||||
except IntegrityError:
|
||||
# Record already exists, skip it
|
||||
pass
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
@@ -91,7 +87,6 @@ class PhpBBService(BaseDBService):
|
||||
pwhash = self._gen_mw_hash(password)
|
||||
self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||
self._dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -43,7 +43,6 @@ class POSTrackerService(BaseDBService):
|
||||
allianceid = 0
|
||||
|
||||
self.dbcursor.execute(self.SQL_ADD_USER, [eveid, username, "%s%s" % (salt, pwhash) , email, corpname, allianceid])
|
||||
transaction.set_dirty()
|
||||
return { 'username': username, 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -57,20 +56,17 @@ class POSTrackerService(BaseDBService):
|
||||
def delete_user(self, uid):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
""" Enable a user """
|
||||
pwhash, salt = self._gen_pwhash(password)
|
||||
self.dbcursor.execute(self.SQL_ENABLE_USER, ["%s%s" % (salt, pwhash), uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -35,7 +35,6 @@ class QMSService(BaseDBService):
|
||||
email = kwargs['user'].email
|
||||
pwhash, salt, cert = self._gen_pwhash(password)
|
||||
self.dbcursor.execute(self.SQL_ADD_USER, [username, username, pwhash, salt, email, cert])
|
||||
transaction.set_dirty()
|
||||
return { 'username': username, 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -50,20 +49,17 @@ class QMSService(BaseDBService):
|
||||
""" Delete a user """
|
||||
#self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||
#self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
#transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
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])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -59,7 +59,9 @@ class TS3Service(BaseService):
|
||||
self.conn.send_command('clientkick', {'clid': client['keys']['clid'], 'reasonid': 5, 'reasonmsg': 'Auth service deleted'})
|
||||
|
||||
ret = self.conn.send_command('clientdbdelete', {'cldbid': user })
|
||||
if ret['id'] == 0:
|
||||
if ret == '0':
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
@@ -67,7 +69,7 @@ class TS3Service(BaseService):
|
||||
user = self._get_userid(uid)
|
||||
if user:
|
||||
ret = self.conn.send_command('servergroupdelclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user })
|
||||
if ret['id'] == 0:
|
||||
if ret == '0':
|
||||
return True
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
@@ -76,7 +78,7 @@ class TS3Service(BaseService):
|
||||
user = self._get_userid(uid)
|
||||
if user:
|
||||
ret = self.conn.send_command('servergroupaddclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user })
|
||||
if ret['id'] == 0:
|
||||
if ret == '0':
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
@@ -131,10 +133,14 @@ class TS3Service(BaseService):
|
||||
|
||||
groups = self.conn.send_command('servergroupsbyclientid', {'cldbid': cldbid })
|
||||
outlist = {}
|
||||
|
||||
if type(groups) == list:
|
||||
for group in groups:
|
||||
outlist[group['keys']['name']] = group['keys']['sgid']
|
||||
return outlist
|
||||
elif type(groups) == dict:
|
||||
outlist[groups['keys']['name']] = groups['keys']['sgid']
|
||||
|
||||
return outlist
|
||||
|
||||
def update_groups(self, uid, groups):
|
||||
""" Update the UID's groups based on the provided list """
|
||||
@@ -150,7 +156,7 @@ class TS3Service(BaseService):
|
||||
for g in groups:
|
||||
if not g.name in tsgrplist:
|
||||
tsgrplist[g.name] = self._create_group(g.name)
|
||||
if not group.name in usrgrplist:
|
||||
if not g.name in usrgrplist:
|
||||
self.conn.send_command('servergroupaddclient', {'sgid': tsgrplist[g.name], 'cldbid': cldbid })
|
||||
usrgrplist[g.name] = tsgrplist[g.name]
|
||||
|
||||
@@ -161,7 +167,7 @@ class TS3Service(BaseService):
|
||||
|
||||
# Remove ignored and admin groups
|
||||
for k, v in usrgrplist.items():
|
||||
if not v == self.settings['auth_sgid'] and not v in self.settings['ignore_groups']:
|
||||
if not int(v) == self.settings['authed_sgid'] and not int(v) in self.settings['ignore_groups']:
|
||||
self.conn.send_command('servergroupdelclient', {'sgid': v, 'cldbid': cldbid })
|
||||
|
||||
return True
|
||||
|
||||
@@ -53,7 +53,6 @@ class MediawikiService(BaseDBService):
|
||||
email = ''
|
||||
pwhash = self._gen_mw_hash(password)
|
||||
self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email, self.default_options])
|
||||
transaction.set_dirty()
|
||||
return { 'username': self._clean_username(username), 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -68,7 +67,6 @@ class MediawikiService(BaseDBService):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
@@ -79,7 +77,6 @@ class MediawikiService(BaseDBService):
|
||||
except IntegrityError:
|
||||
# Record already exists, skip it
|
||||
pass
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
@@ -87,7 +84,6 @@ class MediawikiService(BaseDBService):
|
||||
pwhash = self._gen_mw_hash(password)
|
||||
self.dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||
self.dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
Reference in New Issue
Block a user