comparison src/server/server.py @ 464:bea9788f3170

browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback: - TODO: allow the user to set another XMPP password with the stdui action CHANGE_XMPP_PASSWD_ID
author souliane <souliane@mailoo.org>
date Fri, 23 May 2014 10:00:16 +0200
parents 07433bd892ee
children 33ec27ef4b6a
comparison
equal deleted inserted replaced
463:b62c1cf0dbf7 464:bea9788f3170
611 def _loginAccount(self, request): 611 def _loginAccount(self, request):
612 """Try to authenticate the user with the request information. 612 """Try to authenticate the user with the request information.
613 @param request: request of the register form 613 @param request: request of the register form
614 @return: a constant indicating the state: 614 @return: a constant indicating the state:
615 - BAD REQUEST: something is wrong in the request (bad arguments) 615 - BAD REQUEST: something is wrong in the request (bad arguments)
616 - AUTH ERROR: either the profile (login) or the password is wrong 616 - PROFILE AUTH ERROR: either the profile (login) or the profile password is wrong
617 - XMPP AUTH ERROR: the profile is authenticated but the XMPP password is wrong
617 - ALREADY WAITING: a request has already been submitted for this profile 618 - ALREADY WAITING: a request has already been submitted for this profile
618 - server.NOT_DONE_YET: the profile is being processed, the return 619 - server.NOT_DONE_YET: the profile is being processed, the return
619 value will be given by self._logged or self._logginError 620 value will be given by self._logged or auth_eb
620 """ 621 """
621 try: 622 try:
622 login_ = request.args['login'][0] 623 login_ = request.args['login'][0]
623 password_ = request.args['login_password'][0] 624 password_ = request.args['login_password'][0]
624 except KeyError: 625 except KeyError:
628 raise Exception('No profile_key allowed') 629 raise Exception('No profile_key allowed')
629 630
630 profile_check = self.sat_host.bridge.getProfileName(login_) 631 profile_check = self.sat_host.bridge.getProfileName(login_)
631 if not profile_check or profile_check != login_ or not password_: 632 if not profile_check or profile_check != login_ or not password_:
632 # profiles with empty passwords are restricted to local frontends 633 # profiles with empty passwords are restricted to local frontends
633 return "AUTH ERROR" 634 return "PROFILE AUTH ERROR"
634 635
635 if login_ in self.profiles_waiting: 636 if login_ in self.profiles_waiting:
636 return "ALREADY WAITING" 637 return "ALREADY WAITING"
637 638
638 def auth_eb(ignore=None): 639 def auth_eb(failure):
640 fault = failure.value.faultString
639 self.__cleanWaiting(login_) 641 self.__cleanWaiting(login_)
640 log.info("Profile %s doesn't exist or the submitted password is wrong" % login_) 642 if fault == 'PasswordError':
641 request.write("AUTH ERROR") 643 log.info("Profile %s doesn't exist or the submitted password is wrong" % login_)
644 request.write("PROFILE AUTH ERROR")
645 elif fault == 'SASLAuthError':
646 log.info("The XMPP password of profile %s is wrong" % login_)
647 request.write("XMPP AUTH ERROR")
648 else:
649 log.error('Unmanaged fault string %s in errback for the connection of profile %s' % (fault, login_))
650 request.write('UNMANAGED FAULT STRING: %s' % str(fault))
642 request.finish() 651 request.finish()
643 652
644 self.profiles_waiting[login_] = request 653 self.profiles_waiting[login_] = request
645 d = self.asyncBridgeCall("asyncConnect", login_, password_) 654 d = self.asyncBridgeCall("asyncConnect", login_, password_)
646 d.addCallbacks(lambda connected: self._logged(login_, request) if connected else None, auth_eb) 655 d.addCallbacks(lambda connected: self._logged(login_, request) if connected else None, auth_eb)
728 737
729 _session.notifyOnExpire(onExpire) 738 _session.notifyOnExpire(onExpire)
730 739
731 request.write('LOGGED') 740 request.write('LOGGED')
732 request.finish() 741 request.finish()
733
734 def _logginError(self, login, request, error_type):
735 """Something went wrong during logging in
736 @return: error
737 """
738 self.__cleanWaiting(login)
739 return error_type
740 742
741 def jsonrpc_isConnected(self): 743 def jsonrpc_isConnected(self):
742 _session = self.request.getSession() 744 _session = self.request.getSession()
743 profile = ISATSession(_session).profile 745 profile = ISATSession(_session).profile
744 return self.sat_host.bridge.isConnected(profile) 746 return self.sat_host.bridge.isConnected(profile)
871 del self.signalDeferred[profile] 873 del self.signalDeferred[profile]
872 else: 874 else:
873 if profile not in self.queue: 875 if profile not in self.queue:
874 self.queue[profile] = [] 876 self.queue[profile] = []
875 self.queue[profile].append(("disconnected",)) 877 self.queue[profile].append(("disconnected",))
876
877 def connectionError(self, error_type, profile):
878 assert(self.register) # register must be plugged
879 request = self.register.getWaitingRequest(profile)
880 if request: # The user is trying to log in
881 if error_type == "AUTH_ERROR":
882 _error_t = "AUTH ERROR"
883 else:
884 _error_t = "UNKNOWN"
885 self.register._logginError(profile, request, _error_t)
886 878
887 def render(self, request): 879 def render(self, request):
888 """ 880 """
889 Render method wich reject access if user is not identified 881 Render method wich reject access if user is not identified
890 """ 882 """
1063 sys.exit(1) 1055 sys.exit(1)
1064 1056
1065 def backendReady(dummy): 1057 def backendReady(dummy):
1066 self.bridge.register("connected", self.signal_handler.connected) 1058 self.bridge.register("connected", self.signal_handler.connected)
1067 self.bridge.register("disconnected", self.signal_handler.disconnected) 1059 self.bridge.register("disconnected", self.signal_handler.disconnected)
1068 self.bridge.register("connectionError", self.signal_handler.connectionError)
1069 self.bridge.register("actionResult", self.action_handler.actionResultCb) 1060 self.bridge.register("actionResult", self.action_handler.actionResultCb)
1070 #core 1061 #core
1071 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']: 1062 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']:
1072 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) 1063 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
1073 #plugins 1064 #plugins