Guest User

Untitled

a guest
Apr 7th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. import cx_Oracle
  4.  
  5. class OracleBackend(object):
  6. """Authenticate by attempting to establish an oracle connection.
  7. Uses the database from the settings. The django user module is
  8. still used for management, just not authentication."""
  9. def authenticate(self, username=None, password=None):
  10. try:
  11. dsn = cx_Oracle.makedsn(settings.DATABASE_HOST, settings.DATABASE_PORT, settings.DATABASE_NAME)
  12. connection = cx_Oracle.connect(str('%s/%s@%s' % (username, password, dsn)))
  13. connection.close()
  14. # valid, so log them in:
  15. try:
  16. user = User.objects.get(username=username)
  17. except User.DoesNotExist:
  18. user = User(username=username, password='')
  19. user.set_unusable_password()
  20. user.is_staff = True
  21. user.is_superuser = False
  22.  
  23. user.save()
  24. return user
  25. except: # probably DatabaseError, but I'll catch everything to be safe
  26. return None
Add Comment
Please, Sign In to add comment