# HG changeset patch # User Goffi # Date 1456745865 -3600 # Node ID fa7703642c0eebb7b753f9123fab7d20a0cf45b4 # Parent a12f8d138ae2beb5f68f529dd54ee165838945da server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary diff -r a12f8d138ae2 -r fa7703642c0e src/browser/libervia_main.py --- a/src/browser/libervia_main.py Sun Feb 28 11:54:14 2016 +0100 +++ b/src/browser/libervia_main.py Mon Feb 29 12:37:45 2016 +0100 @@ -95,7 +95,7 @@ self._register = json.RegisterCall() self._register.call('getMenus', self.gotMenus) self._register.call('registerParams', None) - self._register.call('isRegistered', self._isRegisteredCB) + self._register.call('getSessionMetadata', self._getSessionMetadataCB) self.initialised = False self.init_cache = [] # used to cache events until initialisation is done self.cached_params = {} @@ -321,9 +321,9 @@ # XXX: temp, will be reworked in the backed static blog plugin self.menus.addMenu(C.MENU_JID_CONTEXT, (D_(u"User"), D_("Public blog")), callback=main_menu.onPublicBlog) - def _isRegisteredCB(self, result): - registered, warning = result - if not registered: + def _getSessionMetadataCB(self, metadata): + if not metadata['plugged']: + warning = metadata.get("warning") self.panel.setStyleAttribute("opacity", "0.25") # set background transparency self._register_box = register.RegisterBox(self.logged) self._register_box.centerBox() diff -r a12f8d138ae2 -r fa7703642c0e src/browser/sat_browser/json.py --- a/src/browser/sat_browser/json.py Sun Feb 28 11:54:14 2016 +0100 +++ b/src/browser/sat_browser/json.py Mon Feb 29 12:37:45 2016 +0100 @@ -167,7 +167,7 @@ class RegisterCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/register_api", - ["isRegistered", "isConnected", "asyncConnect", "registerParams", "getMenus"]) + ["getSessionMetadata", "isConnected", "asyncConnect", "registerParams", "getMenus"]) class BridgeCall(LiberviaJsonProxy): diff -r a12f8d138ae2 -r fa7703642c0e src/server/server.py --- a/src/server/server.py Sun Feb 28 11:54:14 2016 +0100 +++ b/src/server/server.py Mon Feb 29 12:37:45 2016 +0100 @@ -919,7 +919,7 @@ _session = request.getSession() parsed = jsonrpclib.loads(request.content.read()) method = parsed.get("method") # pylint: disable=E1103 - if method not in ['isRegistered', 'registerParams', 'getMenus']: + if method not in ['getSessionMetadata', 'registerParams', 'getMenus']: #if we don't call these methods, we need to be identified profile = ISATSession(_session).profile if not profile: @@ -1133,17 +1133,26 @@ self.sat_host.bridge.asyncConnect(profile) return server.NOT_DONE_YET - def jsonrpc_isRegistered(self): - """ + def jsonrpc_getSessionMetadata(self): + """Return metadata useful on session start + + @return (dict): metadata which can have the following keys: + "plugged" (bool): True if a profile is already plugged + "warning" (unicode): a security warning message if plugged is False and if it make sense + this key may not be present @return: a couple (registered, message) with: - - registered: True if the user is already registered, False otherwise - - message: a security warning message if registered is False *and* the connection is unsecure, None otherwise + - registered: + - message: """ + metadata = {} _session = self.request.getSession() profile = ISATSession(_session).profile - if bool(profile): - return (True, None) - return (False, self._getSecurityWarning()) + if profile: + metadata["plugged"] = True + else: + metadata["plugged"] = False + metadata["warning"] = self._getSecurityWarning() + return metadata def jsonrpc_registerParams(self): """Register the frontend specific parameters""" @@ -1328,7 +1337,7 @@ Render method with some hacks: - if login is requested, try to login with form data - except login, every method is jsonrpc - - user doesn't need to be authentified for isRegistered, but must be for all other methods + - user doesn't need to be authentified for getSessionMetadata, but must be for all other methods """ filename = self._getFileName(request) filepath = os.path.join(self.upload_dir, filename)