comparison libervia.tac @ 121:2d40b0f5fb37

server side: asynchronous login
author Goffi <goffi@goffi.org>
date Sat, 10 Dec 2011 10:41:40 +0100
parents 2e2e10785c33
children 5cb852d9757e
comparison
equal deleted inserted replaced
120:054b7b3424a3 121:2d40b0f5fb37
230 except: 230 except:
231 warning('Invalid room jid') 231 warning('Invalid room jid')
232 return 232 return
233 self.sat_host.bridge.joinMUC(room_jid.host, room_jid.user, nick, profile) 233 self.sat_host.bridge.joinMUC(room_jid.host, room_jid.user, nick, profile)
234 234
235 def jsonrpc_getRoomJoined(self): 235 def jsonrpc_getRoomsJoined(self):
236 """Return list of room already joined by user""" 236 """Return list of room already joined by user"""
237 profile = ISATSession(self.session).profile 237 profile = ISATSession(self.session).profile
238 return self.sat_host.bridge.getRoomJoined(profile) 238 return self.sat_host.bridge.getRoomsJoined(profile)
239 239
240 def jsonrpc_launchTarotGame(self, other_players): 240 def jsonrpc_launchTarotGame(self, other_players):
241 """Create a room, invite the other players and start a Tarot game""" 241 """Create a room, invite the other players and start a Tarot game"""
242 profile = ISATSession(self.session).profile 242 profile = ISATSession(self.session).profile
243 self.sat_host.bridge.tarotGameLaunch(other_players, profile) 243 self.sat_host.bridge.tarotGameLaunch(other_players, profile)
337 raise Exception('Unknown submit type') 337 raise Exception('Unknown submit type')
338 except KeyError: 338 except KeyError:
339 return "BAD REQUEST" 339 return "BAD REQUEST"
340 340
341 _profile_check = self.sat_host.bridge.getProfileName(_login) 341 _profile_check = self.sat_host.bridge.getProfileName(_login)
342 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login)
343
344 if not _profile_check or _profile_check != _login or _profile_pass != _pass:
345 return "AUTH ERROR"
346 342
347 if self.profiles_waiting.has_key(_login): 343 def profile_pass_cb(_profile_pass):
348 return "ALREADY WAITING" 344 if not _profile_check or _profile_check != _login or _profile_pass != _pass:
345 request.write("AUTH ERROR")
346 request.finish()
347 return
348
349 if self.profiles_waiting.has_key(_login):
350 request.write("ALREADY WAITING")
351 request.finish()
352 return
353
354 if self.sat_host.bridge.isConnected(_login):
355 request.write(self._logged(_login, request, finish=False))
356 request.finish()
357 return
358
359 self.profiles_waiting[_login] = request
360 self.sat_host.bridge.connect(_login)
349 361
350 if self.sat_host.bridge.isConnected(_login): 362 def profile_pass_errback(ignore):
351 return self._logged(_login, request, finish=False) 363 error("INTERNAL ERROR: can't check profile password")
352 364 request.write("AUTH ERROR")
353 self.profiles_waiting[_login] = request 365 request.finish()
354 self.sat_host.bridge.connect(_login) 366
367 d = defer.Deferred()
368 self.sat_host.bridge.asyncGetParamA("Password", "Connection", profile_key=_login, callback=d.callback, errback=d.errback)
369 d.addCallbacks(profile_pass_cb, profile_pass_errback)
370
355 return server.NOT_DONE_YET 371 return server.NOT_DONE_YET
356 372
357 def _postAccountCreation(self, answer_type, id, data, profile): 373 def _postAccountCreation(self, answer_type, id, data, profile):
358 """Called when a account has just been created, 374 """Called when a account has just been created,
359 setup stuff has microblog access""" 375 setup stuff has microblog access"""
564 if request: 580 if request:
565 self.register._logged(profile, request) 581 self.register._logged(profile, request)
566 582
567 def connectionError(self, error_type, profile): 583 def connectionError(self, error_type, profile):
568 assert(self.register) #register must be plugged 584 assert(self.register) #register must be plugged
585 import pdb
586 pdb.set_trace()
569 request = self.register.getWaitingRequest(profile) 587 request = self.register.getWaitingRequest(profile)
570 if request: #The user is trying to log in 588 if request: #The user is trying to log in
571 if error_type == "AUTH_ERROR": 589 if error_type == "AUTH_ERROR":
572 _error_t = "AUTH ERROR" 590 _error_t = "AUTH ERROR"
573 else: 591 else: