Created
January 13, 2010 23:02
Revisions
-
Mark Hepburn revised this gist
Jan 13, 2010 . 2 changed files with 2 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,7 @@ class OracleBackend(object): """Authenticate by attempting to establish an oracle connection. Uses the database from the settings. The django user module is still used for management, just not authentication.""" def authenticate(self, username=None, password=None): try: dsn = cx_Oracle.makedsn(settings.DATABASE_HOST, settings.DATABASE_PORT, settings.DATABASE_NAME) @@ -22,10 +20,6 @@ def authenticate(self, username=None, password=None): user.is_staff = True user.is_superuser = False user.save() return user except: # probably DatabaseError, but I'll catch everything to be safe This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ def set_schema(sender, **kwargs): from django.db import connection from django.conf import settings cursor = connection.cursor() cursor.execute('alter session set current_schema=%s' % settings.DEFAULT_SCHEMA) if set_schema not in connection_created.receivers: connection_created.connect(set_schema) -
markhepburn created this gist
Jan 13, 2010 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ from django.conf import settings from django.contrib.auth.models import User import cx_Oracle class OracleBackend(object): """Authenticate by attempting to establish an oracle connection. Uses the database from the settings. The django user module is still used for management, just not authentication. A random password is used to make sure they don't authenticate against the model backend by accident.""" def authenticate(self, username=None, password=None): try: dsn = cx_Oracle.makedsn(settings.DATABASE_HOST, settings.DATABASE_PORT, settings.DATABASE_NAME) connection = cx_Oracle.connect(str('%s/%s@%s' % (username, password, dsn))) connection.close() # valid, so log them in: try: user = User.objects.get(username=username) except User.DoesNotExist: user = User(username=username, password='') user.set_unusable_password() user.is_staff = True user.is_superuser = False user.save() from ecobaseentry.ecobase.admin import usergroup user.groups.add(usergroup) user.save() return user except: # probably DatabaseError, but I'll catch everything to be safe return None This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ class UserDBConnection(object): """If the user is logged in (assumed if their password is in the session!), the global connection object is updated to use their connection credentials instead of the default Django ones.""" def process_request(self, request): if 'password' in request.session: from django import db from django.conf import settings username = request.user.username password = request.session['password'] db.connection.settings_dict['DATABASE_USER'] = username db.connection.settings_dict['DATABASE_PASSWORD'] = password return None This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ def set_schema(sender, **kwargs): from django.db import connection from django.conf import settings cursor = connection.cursor() cursor.execute("alter session set current_schema=%s" % settings.DEFAULT_SCHEMA) if set_schema not in connection_created.receivers: print 'adding set_schema to signals' connection_created.connect(set_schema)