Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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."""
- 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()
- return user
- except: # probably DatabaseError, but I'll catch everything to be safe
- return None
Add Comment
Please, Sign In to add comment