diff src/server/server.py @ 796:fad9c9f82ae3

browser and server sides: alert the user after he created a new profile using his XMPP account credentials
author souliane <souliane@mailoo.org>
date Tue, 08 Dec 2015 18:11:19 +0100
parents 6a2fd7807770
children 68eadda8a59a
line wrap: on
line diff
--- a/src/server/server.py	Tue Dec 08 15:11:02 2015 +0100
+++ b/src/server/server.py	Tue Dec 08 18:11:19 2015 +0100
@@ -695,14 +695,15 @@
 
 class WaitingRequests(dict):
 
-    def setRequest(self, request, profile):
+    def setRequest(self, request, profile, register_with_ext_jid=False):
         """Add the given profile to the waiting list.
 
         @param request (server.Request): the connection request
         @param profile (str): %(doc_profile)s
+        @param register_with_ext_jid (bool): True if we will try to register the profile with an external XMPP account credentials
         """
         dc = reactor.callLater(BRIDGE_TIMEOUT, self.purgeRequest, profile)
-        self[profile] = (request, dc)
+        self[profile] = (request, dc, register_with_ext_jid)
 
     def purgeRequest(self, profile):
         """Remove the given profile from the waiting list.
@@ -725,6 +726,14 @@
         """
         return self[profile][0] if profile in self else None
 
+    def getRegisterWithExtJid(self, profile):
+        """Get the value of the register_with_ext_jid parameter.
+
+        @param profile (str): %(doc_profile)s
+        @return: bool or None
+        """
+        return self[profile][2] if profile in self else None
+
 
 class Register(JSONRPCMethodManager):
     """This class manage the registration procedure with SàT
@@ -816,16 +825,18 @@
 
         try:
             profile = self.sat_host.bridge.getProfileName(login)
-        except Exception:
-            # try to connect using XMPP credentials instead of SàT profile credentials
+        except Exception:  # XXX: ProfileUnknownError wouldn't work, it's encapsulated
+            # try to create a new sat profile using the XMPP credentials
             profile = login
             connect_method = "asyncConnectWithXMPPCredentials"
+            register_with_ext_jid = True
         else:
             if profile != login or (not password and profile not in self.sat_host.empty_password_allowed_warning_dangerous_list):
                 # profiles with empty passwords are restricted to local frontends
                 request.write(C.PROFILE_AUTH_ERROR)
                 request.finish()
                 return
+            register_with_ext_jid = False
 
             connect_method = "asyncConnect"
 
@@ -851,7 +862,7 @@
                 request.write(fault)
             request.finish()
 
-        self.waiting_profiles.setRequest(request, profile)
+        self.waiting_profiles.setRequest(request, profile, register_with_ext_jid)
         d = self.asyncBridgeCall(connect_method, profile, password)
         d.addCallbacks(lambda connected: self._logged(profile, request) if connected else None, auth_eb)
 
@@ -907,6 +918,7 @@
             - C.PROFILE_LOGGED
             - C.SESSION_ACTIVE
         """
+        register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile)
         self.waiting_profiles.purgeRequest(profile)
         _session = request.getSession()
         sat_session = ISATSession(_session)
@@ -931,7 +943,7 @@
 
         _session.notifyOnExpire(onExpire)
 
-        request.write(C.PROFILE_LOGGED)
+        request.write(C.PROFILE_LOGGED_REGISTERED_WITH_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED)
         request.finish()
 
     def jsonrpc_isConnected(self):
@@ -1056,9 +1068,9 @@
         """
         if not profile in self.sat_host.prof_connected:
             return
-         # FIXME: manage security limit in a dedicated method
-         #        raise an exception if it's not OK
-         #        and read value in sat.conf
+        # FIXME: manage security limit in a dedicated method
+        #        raise an exception if it's not OK
+        #        and read value in sat.conf
         if security_limit >= C.SECURITY_LIMIT:
             log.debug(u"Ignoring action  {action_id}, blocked by security limit".format(action_id=action_id))
             return