comparison libervia/server/server.py @ 1266:6b7f9c3558cc

server, pages: better identities handling: - own identity is now retrieve on connection - use session identities all the time, fixed pages where an empty dict was used - identities and own_jid are alway set in template_data for normal rendering
author Goffi <goffi@goffi.org>
date Tue, 19 May 2020 11:02:32 +0200
parents 92ff09cdd6dd
children e628724530ec
comparison
equal deleted inserted replaced
1265:24e2973378f6 1266:6b7f9c3558cc
49 from sat.tools import config 49 from sat.tools import config
50 from sat.tools.common import regex 50 from sat.tools.common import regex
51 from sat.tools.common import template 51 from sat.tools.common import template
52 from sat.tools.common import uri as common_uri 52 from sat.tools.common import uri as common_uri
53 from sat.tools.common.utils import recursive_update 53 from sat.tools.common.utils import recursive_update
54 from sat.tools.common import data_format
54 import libervia 55 import libervia
55 from libervia.server import websockets 56 from libervia.server import websockets
56 from libervia.server.pages import LiberviaPage 57 from libervia.server.pages import LiberviaPage
57 from libervia.server.utils import quote, ProgressHandler 58 from libervia.server.utils import quote, ProgressHandler
58 from libervia.server.tasks.manager import TasksManager 59 from libervia.server.tasks.manager import TasksManager
1013 kwargs["callback"] = _callback 1014 kwargs["callback"] = _callback
1014 kwargs["errback"] = _errback 1015 kwargs["errback"] = _errback
1015 getattr(self.bridge, method_name)(*args, **kwargs) 1016 getattr(self.bridge, method_name)(*args, **kwargs)
1016 return d 1017 return d
1017 1018
1018 @defer.inlineCallbacks 1019 async def _logged(self, profile, request):
1019 def _logged(self, profile, request):
1020 """Set everything when a user just logged in 1020 """Set everything when a user just logged in
1021 1021
1022 @param profile 1022 @param profile
1023 @param request 1023 @param request
1024 @return: a constant indicating the state: 1024 @return: a constant indicating the state:
1059 self.bridgeCall("disconnect", profile) 1059 self.bridgeCall("disconnect", profile)
1060 1060
1061 session.notifyOnExpire(onExpire) 1061 session.notifyOnExpire(onExpire)
1062 1062
1063 # FIXME: those session infos should be returned by connect or isConnected 1063 # FIXME: those session infos should be returned by connect or isConnected
1064 infos = yield self.bridgeCall("sessionInfosGet", profile) 1064 infos = await self.bridgeCall("sessionInfosGet", profile)
1065 sat_session.jid = jid.JID(infos["jid"]) 1065 sat_session.jid = jid.JID(infos["jid"])
1066 own_bare_jid_s = sat_session.jid.userhost()
1067 own_id_raw = await self.bridgeCall(
1068 "identityGet", own_bare_jid_s, [], True, profile)
1069 sat_session.identities[own_bare_jid_s] = data_format.deserialise(own_id_raw)
1066 sat_session.backend_started = int(infos["started"]) 1070 sat_session.backend_started = int(infos["started"])
1067 1071
1068 state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED 1072 state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED
1069 defer.returnValue(state) 1073 return state
1070 1074
1071 @defer.inlineCallbacks 1075 @defer.inlineCallbacks
1072 def connect(self, request, login, password): 1076 def connect(self, request, login, password):
1073 """log user in 1077 """log user in
1074 1078
1216 ) 1220 )
1217 ) 1221 )
1218 ) 1222 )
1219 #  no, we have to create it 1223 #  no, we have to create it
1220 1224
1221 state = yield self._logged(profile, request) 1225 state = yield defer.ensureDeferred(self._logged(profile, request))
1222 defer.returnValue(state) 1226 defer.returnValue(state)
1223 1227
1224 def registerNewAccount(self, request, login, password, email): 1228 def registerNewAccount(self, request, login, password, email):
1225 """Create a new account, or return error 1229 """Create a new account, or return error
1226 @param request(server.Request): request linked to the session 1230 @param request(server.Request): request linked to the session