comparison 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
comparison
equal deleted inserted replaced
868:a12f8d138ae2 869:fa7703642c0e
917 if request.postpath == ['login']: 917 if request.postpath == ['login']:
918 return self.loginOrRegister(request) 918 return self.loginOrRegister(request)
919 _session = request.getSession() 919 _session = request.getSession()
920 parsed = jsonrpclib.loads(request.content.read()) 920 parsed = jsonrpclib.loads(request.content.read())
921 method = parsed.get("method") # pylint: disable=E1103 921 method = parsed.get("method") # pylint: disable=E1103
922 if method not in ['isRegistered', 'registerParams', 'getMenus']: 922 if method not in ['getSessionMetadata', 'registerParams', 'getMenus']:
923 #if we don't call these methods, we need to be identified 923 #if we don't call these methods, we need to be identified
924 profile = ISATSession(_session).profile 924 profile = ISATSession(_session).profile
925 if not profile: 925 if not profile:
926 #user is not identified, we return a jsonrpc fault 926 #user is not identified, we return a jsonrpc fault
927 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia 927 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
1131 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia 1131 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia
1132 self.waiting_profiles.setRequest(self.request, profile) 1132 self.waiting_profiles.setRequest(self.request, profile)
1133 self.sat_host.bridge.asyncConnect(profile) 1133 self.sat_host.bridge.asyncConnect(profile)
1134 return server.NOT_DONE_YET 1134 return server.NOT_DONE_YET
1135 1135
1136 def jsonrpc_isRegistered(self): 1136 def jsonrpc_getSessionMetadata(self):
1137 """ 1137 """Return metadata useful on session start
1138
1139 @return (dict): metadata which can have the following keys:
1140 "plugged" (bool): True if a profile is already plugged
1141 "warning" (unicode): a security warning message if plugged is False and if it make sense
1142 this key may not be present
1138 @return: a couple (registered, message) with: 1143 @return: a couple (registered, message) with:
1139 - registered: True if the user is already registered, False otherwise 1144 - registered:
1140 - message: a security warning message if registered is False *and* the connection is unsecure, None otherwise 1145 - message:
1141 """ 1146 """
1147 metadata = {}
1142 _session = self.request.getSession() 1148 _session = self.request.getSession()
1143 profile = ISATSession(_session).profile 1149 profile = ISATSession(_session).profile
1144 if bool(profile): 1150 if profile:
1145 return (True, None) 1151 metadata["plugged"] = True
1146 return (False, self._getSecurityWarning()) 1152 else:
1153 metadata["plugged"] = False
1154 metadata["warning"] = self._getSecurityWarning()
1155 return metadata
1147 1156
1148 def jsonrpc_registerParams(self): 1157 def jsonrpc_registerParams(self):
1149 """Register the frontend specific parameters""" 1158 """Register the frontend specific parameters"""
1150 # params = """<params><individual>...</category></individual>""" 1159 # params = """<params><individual>...</category></individual>"""
1151 # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME) 1160 # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
1326 def render(self, request): 1335 def render(self, request):
1327 """ 1336 """
1328 Render method with some hacks: 1337 Render method with some hacks:
1329 - if login is requested, try to login with form data 1338 - if login is requested, try to login with form data
1330 - except login, every method is jsonrpc 1339 - except login, every method is jsonrpc
1331 - user doesn't need to be authentified for isRegistered, but must be for all other methods 1340 - user doesn't need to be authentified for getSessionMetadata, but must be for all other methods
1332 """ 1341 """
1333 filename = self._getFileName(request) 1342 filename = self._getFileName(request)
1334 filepath = os.path.join(self.upload_dir, filename) 1343 filepath = os.path.join(self.upload_dir, filename)
1335 #FIXME: the uploaded file is fully loaded in memory at form parsing time so far 1344 #FIXME: the uploaded file is fully loaded in memory at form parsing time so far
1336 # (see twisted.web.http.Request.requestReceived). A custom requestReceived should 1345 # (see twisted.web.http.Request.requestReceived). A custom requestReceived should