import os, sys
import site
sys.path = ['<Dir holding Django app>'] + sys.path
site.addsitedir('<Virtualenv root>/lib/python2.6/site-packages')
sys.stdout = sys.stderr
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_site.settings'
from django import db
from django.conf import settings
from django.contrib.sessions.backends.db import SessionStore
from django.contrib.auth.models import User
from django.core.handlers.wsgi import WSGIRequest
def allow_access(environ, host):
"""
Authentication handler that checks if user is logged in
"""
# Fake this, allow_access gets a stripped environ
environ['wsgi.input'] = None
request = WSGIRequest(environ)
errors = environ['wsgi.errors']
try:
if <Authorized>:
return True
else:
return False
except Exception as e:
errors.write('Exception: %s\n' % e)
return False
finally:
db.connection.close()
Comments
Note, You need mod_wsgi > 3.0 to have access to the Cookies from the provided environ.
#