mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 14:22:16 +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'.
|
||||
DATABASE_NAME = 'dreddit_sso.db' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = '' # Not used with sqlite3.
|
||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'NAME': 'dreddit_sso.db',
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'USER': '',
|
||||
'PASSWORD': '',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,17 +73,7 @@ class BaseDBService(BaseService):
|
||||
@property
|
||||
def db(self):
|
||||
if not hasattr(self, '_db'):
|
||||
# Use the master DB settings, bar the 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,})
|
||||
|
||||
self._db = connections[self.settings['database_name']]
|
||||
return self._db
|
||||
|
||||
@property
|
||||
@@ -92,9 +82,3 @@ class BaseDBService(BaseService):
|
||||
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
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import crypt
|
||||
import random
|
||||
import time
|
||||
from django.db import load_backend, transaction
|
||||
from django.db import transaction
|
||||
from sso.services import BaseDBService
|
||||
import settings
|
||||
|
||||
@@ -46,12 +46,12 @@ class MiningBuddyService(BaseDBService):
|
||||
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
|
||||
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.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
|
||||
return { 'username': self._clean_username(username), 'password': password }
|
||||
|
||||
@@ -66,20 +66,20 @@ class MiningBuddyService(BaseDBService):
|
||||
def delete_user(self, uid):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
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])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -41,7 +41,7 @@ class PhpBBService(BaseDBService):
|
||||
pwhash = self._gen_hash(password)
|
||||
|
||||
self._dbcursor.execute(self.SQL_ADD_USER, [username, pwhash, email])
|
||||
self._db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
|
||||
self.update_groups(username)
|
||||
return { 'username': username, 'password': password }
|
||||
@@ -56,12 +56,12 @@ class PhpBBService(BaseDBService):
|
||||
row = self._dbcursor.fetchone()
|
||||
if not row:
|
||||
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])
|
||||
row = self._dbcursor.fetchone()
|
||||
|
||||
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):
|
||||
""" Check if the username exists """
|
||||
@@ -83,16 +83,15 @@ class PhpBBService(BaseDBService):
|
||||
except IntegrityError:
|
||||
# Record already exists, skip it
|
||||
pass
|
||||
self._db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
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()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import hashlib
|
||||
import random
|
||||
from django.db import load_backend, transaction, IntegrityError
|
||||
from django.db import transaction, IntegrityError
|
||||
from sso.services import BaseDBService
|
||||
import settings
|
||||
|
||||
@@ -37,7 +37,7 @@ class POSTrackerService(BaseDBService):
|
||||
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.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return { 'username': username, 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -51,20 +51,20 @@ class POSTrackerService(BaseDBService):
|
||||
def delete_user(self, uid):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
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])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -35,7 +35,7 @@ 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])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return { 'username': username, 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -50,20 +50,20 @@ class QMSService(BaseDBService):
|
||||
""" Delete a user """
|
||||
#self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||
#self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
#self.db.connection.commit()
|
||||
#transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
""" Disable a user """
|
||||
self.dbcursor.execute(self.SQL_DIS_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
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])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
@@ -53,7 +53,7 @@ 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])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return { 'username': self._clean_username(username), 'password': password }
|
||||
|
||||
def check_user(self, username):
|
||||
@@ -68,7 +68,7 @@ class MediawikiService(BaseDBService):
|
||||
""" Delete a user """
|
||||
self.dbcursor.execute(self.SQL_DEL_REV, [uid])
|
||||
self.dbcursor.execute(self.SQL_DEL_USER, [uid])
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def disable_user(self, uid):
|
||||
@@ -79,16 +79,15 @@ class MediawikiService(BaseDBService):
|
||||
except IntegrityError:
|
||||
# Record already exists, skip it
|
||||
pass
|
||||
self.db.connection.commit()
|
||||
transaction.set_dirty()
|
||||
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()
|
||||
transaction.set_dirty()
|
||||
return True
|
||||
|
||||
def reset_password(self, uid, password):
|
||||
|
||||
Reference in New Issue
Block a user