comparison 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
comparison
equal deleted inserted replaced
795:a6b39838353f 796:fad9c9f82ae3
693 return self.sat_host.bridge.skipOTR(profile) 693 return self.sat_host.bridge.skipOTR(profile)
694 694
695 695
696 class WaitingRequests(dict): 696 class WaitingRequests(dict):
697 697
698 def setRequest(self, request, profile): 698 def setRequest(self, request, profile, register_with_ext_jid=False):
699 """Add the given profile to the waiting list. 699 """Add the given profile to the waiting list.
700 700
701 @param request (server.Request): the connection request 701 @param request (server.Request): the connection request
702 @param profile (str): %(doc_profile)s 702 @param profile (str): %(doc_profile)s
703 @param register_with_ext_jid (bool): True if we will try to register the profile with an external XMPP account credentials
703 """ 704 """
704 dc = reactor.callLater(BRIDGE_TIMEOUT, self.purgeRequest, profile) 705 dc = reactor.callLater(BRIDGE_TIMEOUT, self.purgeRequest, profile)
705 self[profile] = (request, dc) 706 self[profile] = (request, dc, register_with_ext_jid)
706 707
707 def purgeRequest(self, profile): 708 def purgeRequest(self, profile):
708 """Remove the given profile from the waiting list. 709 """Remove the given profile from the waiting list.
709 710
710 @param profile (str): %(doc_profile)s 711 @param profile (str): %(doc_profile)s
722 723
723 @param profile (str): %(doc_profile)s 724 @param profile (str): %(doc_profile)s
724 @return: the waiting request or None 725 @return: the waiting request or None
725 """ 726 """
726 return self[profile][0] if profile in self else None 727 return self[profile][0] if profile in self else None
728
729 def getRegisterWithExtJid(self, profile):
730 """Get the value of the register_with_ext_jid parameter.
731
732 @param profile (str): %(doc_profile)s
733 @return: bool or None
734 """
735 return self[profile][2] if profile in self else None
727 736
728 737
729 class Register(JSONRPCMethodManager): 738 class Register(JSONRPCMethodManager):
730 """This class manage the registration procedure with SàT 739 """This class manage the registration procedure with SàT
731 It provide an api for the browser, check password and setup the web server""" 740 It provide an api for the browser, check password and setup the web server"""
814 if login_jid.host == new_account_domain: 823 if login_jid.host == new_account_domain:
815 login = login_jid.user 824 login = login_jid.user
816 825
817 try: 826 try:
818 profile = self.sat_host.bridge.getProfileName(login) 827 profile = self.sat_host.bridge.getProfileName(login)
819 except Exception: 828 except Exception: # XXX: ProfileUnknownError wouldn't work, it's encapsulated
820 # try to connect using XMPP credentials instead of SàT profile credentials 829 # try to create a new sat profile using the XMPP credentials
821 profile = login 830 profile = login
822 connect_method = "asyncConnectWithXMPPCredentials" 831 connect_method = "asyncConnectWithXMPPCredentials"
832 register_with_ext_jid = True
823 else: 833 else:
824 if profile != login or (not password and profile not in self.sat_host.empty_password_allowed_warning_dangerous_list): 834 if profile != login or (not password and profile not in self.sat_host.empty_password_allowed_warning_dangerous_list):
825 # profiles with empty passwords are restricted to local frontends 835 # profiles with empty passwords are restricted to local frontends
826 request.write(C.PROFILE_AUTH_ERROR) 836 request.write(C.PROFILE_AUTH_ERROR)
827 request.finish() 837 request.finish()
828 return 838 return
839 register_with_ext_jid = False
829 840
830 connect_method = "asyncConnect" 841 connect_method = "asyncConnect"
831 842
832 if self.waiting_profiles.getRequest(profile): 843 if self.waiting_profiles.getRequest(profile):
833 request.write(C.ALREADY_WAITING) 844 request.write(C.ALREADY_WAITING)
849 else: 860 else:
850 log.error(u'Unmanaged fault string "%s" in errback for the connection of profile %s' % (fault, profile)) 861 log.error(u'Unmanaged fault string "%s" in errback for the connection of profile %s' % (fault, profile))
851 request.write(fault) 862 request.write(fault)
852 request.finish() 863 request.finish()
853 864
854 self.waiting_profiles.setRequest(request, profile) 865 self.waiting_profiles.setRequest(request, profile, register_with_ext_jid)
855 d = self.asyncBridgeCall(connect_method, profile, password) 866 d = self.asyncBridgeCall(connect_method, profile, password)
856 d.addCallbacks(lambda connected: self._logged(profile, request) if connected else None, auth_eb) 867 d.addCallbacks(lambda connected: self._logged(profile, request) if connected else None, auth_eb)
857 868
858 def _registerNewAccount(self, request): 869 def _registerNewAccount(self, request):
859 """Create a new account, or return error 870 """Create a new account, or return error
905 @param request 916 @param request
906 @return: a constant indicating the state: 917 @return: a constant indicating the state:
907 - C.PROFILE_LOGGED 918 - C.PROFILE_LOGGED
908 - C.SESSION_ACTIVE 919 - C.SESSION_ACTIVE
909 """ 920 """
921 register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile)
910 self.waiting_profiles.purgeRequest(profile) 922 self.waiting_profiles.purgeRequest(profile)
911 _session = request.getSession() 923 _session = request.getSession()
912 sat_session = ISATSession(_session) 924 sat_session = ISATSession(_session)
913 if sat_session.profile: 925 if sat_session.profile:
914 log.error(('/!\\ Session has already a profile, this should NEVER happen!')) 926 log.error(('/!\\ Session has already a profile, this should NEVER happen!'))
929 #and now we disconnect the profile 941 #and now we disconnect the profile
930 self.sat_host.bridge.disconnect(profile) 942 self.sat_host.bridge.disconnect(profile)
931 943
932 _session.notifyOnExpire(onExpire) 944 _session.notifyOnExpire(onExpire)
933 945
934 request.write(C.PROFILE_LOGGED) 946 request.write(C.PROFILE_LOGGED_REGISTERED_WITH_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED)
935 request.finish() 947 request.finish()
936 948
937 def jsonrpc_isConnected(self): 949 def jsonrpc_isConnected(self):
938 _session = self.request.getSession() 950 _session = self.request.getSession()
939 profile = ISATSession(_session).profile 951 profile = ISATSession(_session).profile
1054 @param security_limit(int): %(doc_security_limit)s 1066 @param security_limit(int): %(doc_security_limit)s
1055 @param profile(unicode): %(doc_profile)s 1067 @param profile(unicode): %(doc_profile)s
1056 """ 1068 """
1057 if not profile in self.sat_host.prof_connected: 1069 if not profile in self.sat_host.prof_connected:
1058 return 1070 return
1059 # FIXME: manage security limit in a dedicated method 1071 # FIXME: manage security limit in a dedicated method
1060 # raise an exception if it's not OK 1072 # raise an exception if it's not OK
1061 # and read value in sat.conf 1073 # and read value in sat.conf
1062 if security_limit >= C.SECURITY_LIMIT: 1074 if security_limit >= C.SECURITY_LIMIT:
1063 log.debug(u"Ignoring action {action_id}, blocked by security limit".format(action_id=action_id)) 1075 log.debug(u"Ignoring action {action_id}, blocked by security limit".format(action_id=action_id))
1064 return 1076 return
1065 signal_data = ("actionNew", (action_data, action_id, security_limit)) 1077 signal_data = ("actionNew", (action_data, action_id, security_limit))
1066 try: 1078 try: