changeset 869:fa7703642c0e

server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 12:37:45 +0100
parents a12f8d138ae2
children a05f3b24f2ec
files src/browser/libervia_main.py src/browser/sat_browser/json.py src/server/server.py
diffstat 3 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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()
--- 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):
--- 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)