from django db import connection backend import settings pdb class Aut

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.db import connection, backend
import settings, pdb
class AuthMiddleware(object):
def process_view(self, request, view, args, kwargs):
# pdb.set_trace()
assert hasattr(request, 'session'), "Requires session middleware"
if 'username' in request.session and 'password' in request.session:
settings.DATABASE_USER = request.session['username']
settings.DATABASE_PASSWORD = request.session['password']
connection.close()
opt={
'DATABASE_ENGINE': settings.DATABASE_ENGINE,
'DATABASE_NAME': settings.DATABASE_NAME,
'DATABASE_USER': settings.DATABASE_USER,
'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
'DATABASE_HOST': settings.DATABASE_HOST,
'DATABASE_PORT': settings.DATABASE_PORT,
}
backend.DatabaseWrapper(**opt)
return None