changeset 121:2d40b0f5fb37

server side: asynchronous login
author Goffi <goffi@goffi.org>
date Sat, 10 Dec 2011 10:41:40 +0100
parents 054b7b3424a3
children 397a88b340f3
files browser_side/register.py libervia.tac
diffstat 2 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/register.py	Thu Jul 07 19:03:06 2011 +0200
+++ b/browser_side/register.py	Sat Dec 10 10:41:40 2011 +0100
@@ -157,7 +157,7 @@
     def onSubmitComplete(self, event):
         result = event.getResults()
         if result == "AUTH ERROR":
-            Window.alert('You login and/or password is incorrect. Please try again')
+            Window.alert('Your login and/or password is incorrect. Please try again')
         elif result == "LOGGED":
             self.callback()
         elif result == "SESSION_ACTIVE":
--- a/libervia.tac	Thu Jul 07 19:03:06 2011 +0200
+++ b/libervia.tac	Sat Dec 10 10:41:40 2011 +0100
@@ -232,10 +232,10 @@
             return
         self.sat_host.bridge.joinMUC(room_jid.host, room_jid.user, nick, profile)
 
-    def jsonrpc_getRoomJoined(self):
+    def jsonrpc_getRoomsJoined(self):
         """Return list of room already joined by user"""
         profile = ISATSession(self.session).profile
-        return self.sat_host.bridge.getRoomJoined(profile) 
+        return self.sat_host.bridge.getRoomsJoined(profile) 
 
     def jsonrpc_launchTarotGame(self, other_players):
         """Create a room, invite the other players and start a Tarot game"""
@@ -339,19 +339,35 @@
             return "BAD REQUEST"
 
         _profile_check = self.sat_host.bridge.getProfileName(_login)
-        _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login)
-
-        if not _profile_check or _profile_check != _login or _profile_pass != _pass:
-            return "AUTH ERROR"
         
-        if self.profiles_waiting.has_key(_login):
-            return "ALREADY WAITING"
+        def profile_pass_cb(_profile_pass):
+            if not _profile_check or _profile_check != _login or _profile_pass != _pass:
+                request.write("AUTH ERROR")
+                request.finish()
+                return
+            
+            if self.profiles_waiting.has_key(_login):
+                request.write("ALREADY WAITING")
+                request.finish()
+                return
+            
+            if self.sat_host.bridge.isConnected(_login):
+                request.write(self._logged(_login, request, finish=False))
+                request.finish()
+                return
+
+            self.profiles_waiting[_login] = request
+            self.sat_host.bridge.connect(_login) 
         
-        if self.sat_host.bridge.isConnected(_login):
-            return self._logged(_login, request, finish=False)
+        def profile_pass_errback(ignore):
+            error("INTERNAL ERROR: can't check profile password")
+            request.write("AUTH ERROR")
+            request.finish()
+        
+        d = defer.Deferred()
+        self.sat_host.bridge.asyncGetParamA("Password", "Connection", profile_key=_login, callback=d.callback, errback=d.errback)
+        d.addCallbacks(profile_pass_cb, profile_pass_errback)
 
-        self.profiles_waiting[_login] = request
-        self.sat_host.bridge.connect(_login) 
         return server.NOT_DONE_YET
 
     def _postAccountCreation(self, answer_type, id, data, profile):
@@ -566,6 +582,8 @@
 
     def connectionError(self, error_type, profile):
         assert(self.register) #register must be plugged
+        import pdb
+        pdb.set_trace()
         request = self.register.getWaitingRequest(profile)
         if request: #The user is trying to log in
             if error_type == "AUTH_ERROR":