From: Ciro Scognamiglio Date: Thu, 16 Apr 2015 11:21:35 +0000 (+0200) Subject: rollback to django session management X-Git-Tag: myslice-1.3~37^2~9 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=47875c18877f9c482861cdede4832b94f13a11c3;hp=d46e16e2f5947147a208ee9721660639330e0d6b;p=unfold.git rollback to django session management --- diff --git a/localauth/manifoldbackend.py b/localauth/manifoldbackend.py index c2899e9d..e52b1753 100644 --- a/localauth/manifoldbackend.py +++ b/localauth/manifoldbackend.py @@ -7,7 +7,7 @@ from manifold.core.query import Query from myslice.settings import config, logger, DEBUG -from unfold.sessioncache import SessionCache +# from unfold.sessioncache import SessionCache # Name my backend 'ManifoldBackend' class ManifoldBackend: @@ -33,11 +33,11 @@ class ManifoldBackend: logger.error("GetSession failed: {}".format(sessions_result.error())) return session = sessions[0] - logger.debug("SESSION : {}".format(session)) + logger.debug("SESSION : {}".format(session.keys())) # Change to session authentication - session_auth = {'AuthMethod': 'session', 'session': session['session']} - api.auth = session_auth + api.auth = {'AuthMethod': 'session', 'session': session['session']} + #api.auth = session_auth self.api = api # Get account details @@ -49,10 +49,13 @@ class ManifoldBackend: return person = persons[0] logger.debug("PERSON : {}".format(person)) + + request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']} + #logger.info("{} {} <{}> logged in"\ # .format(person['config']['first_name'], person['config']['last_name'], person['config']['email'])) - SessionCache().store_auth(request, session_auth) + #SessionCache().store_auth(request, session_auth) except ManifoldException as e: logger.error("ManifoldException in Auth Backend: {}".format(e.manifold_result)) diff --git a/manifoldapi/manifoldapi.py b/manifoldapi/manifoldapi.py index c215b6c1..29236c0f 100644 --- a/manifoldapi/manifoldapi.py +++ b/manifoldapi/manifoldapi.py @@ -9,7 +9,7 @@ from django.shortcuts import redirect from manifold.core.result_value import ResultValue from manifoldresult import ManifoldResult, ManifoldCode, ManifoldException, truncate_result -from unfold.sessioncache import SessionCache +# from unfold.sessioncache import SessionCache from myslice.settings import config, logger @@ -92,8 +92,10 @@ def _execute_query(request, query, manifold_api_session_auth): # but most importantly there is a need to refine that test, since # code==2 does not necessarily mean an expired session # XXX only if we know it is the issue - SessionCache().end_session(request) + #SessionCache().end_session(request) # Flush django session + del request.session['manifold'] + request.session.flush() #raise Exception, 'Error running query: {}'.format(result) @@ -107,13 +109,18 @@ def _execute_query(request, query, manifold_api_session_auth): def execute_query(request, query): - manifold_api_session_auth = SessionCache().get_auth(request) - if not manifold_api_session_auth: + logger.debug("EXECUTE QUERY: request - {}".format(request.session.items())) + + if not 'manifold' in request.session or not 'auth' in request.session['manifold']: + #manifold_api_session_auth = SessionCache().get_auth(request) + #if not manifold_api_session_auth: request.session.flush() #raise Exception, "User not authenticated" host = request.get_host() return redirect('/') + manifold_api_session_auth = request.session['manifold']['auth'] + return _execute_query(request, query, manifold_api_session_auth) def execute_admin_query(request, query): diff --git a/manifoldapi/manifoldproxy.py b/manifoldapi/manifoldproxy.py index a5bc20da..eba37bb8 100644 --- a/manifoldapi/manifoldproxy.py +++ b/manifoldapi/manifoldproxy.py @@ -12,7 +12,7 @@ from manifoldapi import ManifoldAPI from manifoldresult import ManifoldException from manifold.util.log import Log -from unfold.sessioncache import SessionCache +# from unfold.sessioncache import SessionCache from myslice.settings import config, logger @@ -61,8 +61,11 @@ def proxy (request,format): admin_user, admin_password = config.manifold_admin_user_password() manifold_api_session_auth = {'AuthMethod': 'password', 'Username': admin_user, 'AuthString': admin_password} else: - manifold_api_session_auth = SessionCache().get_auth(request) - if not manifold_api_session_auth: + if 'manifold' in request.session: + manifold_api_session_auth = request.session['manifold']['auth'] + else: + #manifold_api_session_auth = SessionCache().get_auth(request) + #if not manifold_api_session_auth: return HttpResponse (json.dumps({'code':0,'value':[]}), content_type="application/json") if debug_empty and manifold_query.action.lower()=='get': diff --git a/unfold/page.py b/unfold/page.py index f8f4eb3b..a9228ecc 100644 --- a/unfold/page.py +++ b/unfold/page.py @@ -99,16 +99,29 @@ class Page: # needs to be called explicitly and only when metadata is actually required # in particular user needs to be logged def get_metadata (self): - cached_metadata = SessionCache().get_metadata(self.request) - if cached_metadata and isinstance(cached_metadata, MetaData): + # look in session's cache - we don't want to retrieve this for every request + session=self.request.session + + if 'manifold' not in session: + session['manifold'] = {} + manifold = session['manifold'] + + # if cached, use it + if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData): + +# cached_metadata = SessionCache().get_metadata(self.request) +# if cached_metadata and isinstance(cached_metadata, MetaData): logger.debug("Page.get_metadata: return cached value") - return cached_metadata + return manifold['metadata'] +# return cached_metadata metadata_auth = {'AuthMethod':'anonymous'} metadata = MetaData (metadata_auth) metadata.fetch(self.request) - SessionCache().store_metadata(self.request, metadata) + # store it for next time + manifold['metadata']=metadata +# SessionCache().store_metadata(self.request, metadata) logger.debug("Page.get_metadata: return new value") return metadata