mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 22:32:15 +00:00
Switch SSO Service API layer to use the new Django 1.2 ORM layer
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
DATABASES = {
|
||||||
DATABASE_NAME = 'dreddit_sso.db' # Or path to database file if using sqlite3.
|
'default': {
|
||||||
DATABASE_USER = '' # Not used with sqlite3.
|
'NAME': 'dreddit_sso.db',
|
||||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
'USER': '',
|
||||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
'PASSWORD': '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,17 +73,7 @@ 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
|
self._db = connections[self.settings['database_name']]
|
||||||
backend = load_backend(settings.DATABASE_ENGINE)
|
|
||||||
self._db = backend.DatabaseWrapper({
|
|
||||||
'DATABASE_HOST': settings.DATABASE_HOST,
|
|
||||||
'DATABASE_NAME': self.settings['database_name'],
|
|
||||||
'DATABASE_OPTIONS': {},
|
|
||||||
'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
|
|
||||||
'DATABASE_PORT': settings.DATABASE_PORT,
|
|
||||||
'DATABASE_USER': settings.DATABASE_USER,
|
|
||||||
'TIME_ZONE': settings.TIME_ZONE,})
|
|
||||||
|
|
||||||
return self._db
|
return self._db
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -92,9 +82,3 @@ class BaseDBService(BaseService):
|
|||||||
self._dbcursor = self.db.cursor()
|
self._dbcursor = self.db.cursor()
|
||||||
return self._dbcursor
|
return self._dbcursor
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
if hasattr(self, '_db'):
|
|
||||||
self.db.connection.commit()
|
|
||||||
self.db.close()
|
|
||||||
self.db = None
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import crypt
|
import crypt
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from django.db import load_backend, transaction
|
from django.db import transaction
|
||||||
from sso.services import BaseDBService
|
from sso.services import BaseDBService
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@@ -46,12 +46,12 @@ class MiningBuddyService(BaseDBService):
|
|||||||
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()
|
transaction.set_dirty()
|
||||||
|
|
||||||
userid = self.dbcursor.lastrowid
|
userid = self.dbcursor.lastrowid
|
||||||
api = kwargs['character'].eveaccount_set.all()[0]
|
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])
|
self.dbcursor.execute(self.SQL_ADD_API, [userid, int(time.time()), api.api_user_id, api.api_key, kwargs['character'].id])
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
|
|
||||||
return { 'username': self._clean_username(username), 'password': password }
|
return { 'username': self._clean_username(username), 'password': password }
|
||||||
|
|
||||||
@@ -66,20 +66,20 @@ class MiningBuddyService(BaseDBService):
|
|||||||
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()
|
transaction.set_dirty()
|
||||||
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()
|
transaction.set_dirty()
|
||||||
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_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()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class PhpBBService(BaseDBService):
|
|||||||
pwhash = self._gen_hash(password)
|
pwhash = self._gen_hash(password)
|
||||||
|
|
||||||
self._dbcursor.execute(self.SQL_ADD_USER, [username, pwhash, email])
|
self._dbcursor.execute(self.SQL_ADD_USER, [username, pwhash, email])
|
||||||
self._db.connection.commit()
|
transaction.set_dirty()
|
||||||
|
|
||||||
self.update_groups(username)
|
self.update_groups(username)
|
||||||
return { 'username': username, 'password': password }
|
return { 'username': username, 'password': password }
|
||||||
@@ -56,12 +56,12 @@ class PhpBBService(BaseDBService):
|
|||||||
row = self._dbcursor.fetchone()
|
row = self._dbcursor.fetchone()
|
||||||
if not row:
|
if not row:
|
||||||
self._dbcursor.execute(self.SQL_ADD_GROUP, [group.name])
|
self._dbcursor.execute(self.SQL_ADD_GROUP, [group.name])
|
||||||
self._db.connection.commit()
|
transaction.set_dirty()
|
||||||
self._dbcursor.execute(self.SQL_GET_GROUP, [group.name])
|
self._dbcursor.execute(self.SQL_GET_GROUP, [group.name])
|
||||||
row = self._dbcursor.fetchone()
|
row = self._dbcursor.fetchone()
|
||||||
|
|
||||||
self._dbcursor.execute(self.SQL_ADD_USER_GROUP, [row['group_id'], user_id])
|
self._dbcursor.execute(self.SQL_ADD_USER_GROUP, [row['group_id'], user_id])
|
||||||
self._db.connection.commit()
|
transaction.set_dirty()
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
""" Check if the username exists """
|
""" Check if the username exists """
|
||||||
@@ -83,16 +83,15 @@ class PhpBBService(BaseDBService):
|
|||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# Record already exists, skip it
|
# Record already exists, skip it
|
||||||
pass
|
pass
|
||||||
self._db.connection.commit()
|
transaction.set_dirty()
|
||||||
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._dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
self._dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
||||||
self._db.connection.commit()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
from django.db import load_backend, transaction, IntegrityError
|
from django.db import transaction, IntegrityError
|
||||||
from sso.services import BaseDBService
|
from sso.services import BaseDBService
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class POSTrackerService(BaseDBService):
|
|||||||
eveid = kwargs['character'].eveaccount_set.all()[0].api_user_id
|
eveid = kwargs['character'].eveaccount_set.all()[0].api_user_id
|
||||||
|
|
||||||
self.dbcursor.execute(self.SQL_ADD_USER, [eveid, username, "%s%s" % (salt, pwhash) , email])
|
self.dbcursor.execute(self.SQL_ADD_USER, [eveid, username, "%s%s" % (salt, pwhash) , email])
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
return { 'username': username, 'password': password }
|
return { 'username': username, 'password': password }
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
@@ -51,20 +51,20 @@ class POSTrackerService(BaseDBService):
|
|||||||
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()
|
transaction.set_dirty()
|
||||||
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()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def enable_user(self, uid, password):
|
def enable_user(self, uid, password):
|
||||||
""" Enable a user """
|
""" Enable a user """
|
||||||
pwhash, salt = self._gen_pwhash(password)
|
pwhash, salt = self._gen_pwhash(password)
|
||||||
self.dbcursor.execute(self.SQL_ENABLE_USER, ["%s%s" % (salt, pwhash), uid])
|
self.dbcursor.execute(self.SQL_ENABLE_USER, ["%s%s" % (salt, pwhash), uid])
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class QMSService(BaseDBService):
|
|||||||
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()
|
transaction.set_dirty()
|
||||||
return { 'username': username, 'password': password }
|
return { 'username': username, 'password': password }
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
@@ -50,20 +50,20 @@ class QMSService(BaseDBService):
|
|||||||
""" 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()
|
#transaction.set_dirty()
|
||||||
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()
|
transaction.set_dirty()
|
||||||
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()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class MediawikiService(BaseDBService):
|
|||||||
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.default_options])
|
self.dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email, self.default_options])
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
return { 'username': self._clean_username(username), 'password': password }
|
return { 'username': self._clean_username(username), 'password': password }
|
||||||
|
|
||||||
def check_user(self, username):
|
def check_user(self, username):
|
||||||
@@ -68,7 +68,7 @@ class MediawikiService(BaseDBService):
|
|||||||
""" 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()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disable_user(self, uid):
|
def disable_user(self, uid):
|
||||||
@@ -79,16 +79,15 @@ class MediawikiService(BaseDBService):
|
|||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# Record already exists, skip it
|
# Record already exists, skip it
|
||||||
pass
|
pass
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
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.dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
self.dbcursor.execute(self.SQL_ENABLE_GROUP, [uid])
|
||||||
self.db.connection.commit()
|
transaction.set_dirty()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset_password(self, uid, password):
|
def reset_password(self, uid, password):
|
||||||
|
|||||||
Reference in New Issue
Block a user