diff src/server/server.py @ 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 12d0e7bd0dd1
children 54f6c5b86a87
line wrap: on
line diff
--- 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)