# HG changeset patch # User Goffi # Date 1527850525 -7200 # Node ID 9c41b7e91172b2568d0b7db363b6093e4abe3593 # Parent 3996acd7c796f37f6834587b3a68060357b674ca server: set jid and started time in session on log-in: session make the difference between local libervia session ("started"), and backend session ("backend_started") diff -r 3996acd7c796 -r 9c41b7e91172 src/server/server.py --- a/src/server/server.py Fri Jun 01 12:52:14 2018 +0200 +++ b/src/server/server.py Fri Jun 01 12:55:25 2018 +0200 @@ -1569,6 +1569,7 @@ getattr(self.bridge, method_name)(*args, **kwargs) return d + @defer.inlineCallbacks def _logged(self, profile, request): """Set everything when a user just logged in @@ -1581,8 +1582,8 @@ """ register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile) self.waiting_profiles.purgeRequest(profile) - _session = request.getSession() - sat_session = session_iface.ISATSession(_session) + session = request.getSession() + sat_session = session_iface.ISATSession(session) if sat_session.profile: log.error(_(u'/!\\ Session has already a profile, this should NEVER happen!')) raise failure.Failure(exceptions.ConflictError("Already active")) @@ -1606,9 +1607,15 @@ #and now we disconnect the profile self.bridge.disconnect(profile) - _session.notifyOnExpire(onExpire) + session.notifyOnExpire(onExpire) - return C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED + # FIXME: those session infos should be returned by connect or isConnected + infos = yield self.bridgeCall('sessionInfosGet', profile) + sat_session.jid = jid.JID(infos['jid']) + sat_session.backend_started = int(infos['started']) + + state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED + defer.returnValue(state) @defer.inlineCallbacks def connect(self, request, login, password): @@ -1725,7 +1732,9 @@ defer.returnValue(C.SESSION_ACTIVE) log.info(_(u"profile {profile} was already connected in backend".format(profile=profile))) # no, we have to create it - defer.returnValue(self._logged(profile, request)) + + state = yield self._logged(profile, request) + defer.returnValue(state) def registerNewAccount(self, request, login, password, email): """Create a new account, or return error diff -r 3996acd7c796 -r 9c41b7e91172 src/server/session_iface.py --- a/src/server/session_iface.py Fri Jun 01 12:52:14 2018 +0200 +++ b/src/server/session_iface.py Fri Jun 01 12:55:25 2018 +0200 @@ -21,6 +21,7 @@ from libervia.server.constants import Const as C import os.path import shortuuid +import time FLAGS_KEY = '_flags' @@ -37,6 +38,9 @@ def __init__(self, session): self.profile = None self.jid = None + self.started = time.time() + # time when the backend session was started + self.backend_started = None self.uuid = unicode(shortuuid.uuid()) self.identities = data_objects.Identities() self.csrf_token = unicode(shortuuid.uuid())