comparison src/server/server.py @ 871:54f6c5b86a87

server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 12:40:14 +0100
parents fa7703642c0e
children 0cf250066b8a
comparison
equal deleted inserted replaced
870:a05f3b24f2ec 871:54f6c5b86a87
941 submit_type = request.args['submit_type'][0] 941 submit_type = request.args['submit_type'][0]
942 except KeyError: 942 except KeyError:
943 return C.BAD_REQUEST 943 return C.BAD_REQUEST
944 944
945 if submit_type == 'register': 945 if submit_type == 'register':
946 if not self.sat_host.options["allow_registration"]:
947 log.warning(u"Registration received while it is not allowed, hack attempt?")
948 return exceptions.PermissionError(u"Registration is not allowed on this server")
946 return self._registerNewAccount(request) 949 return self._registerNewAccount(request)
947 elif submit_type == 'login': 950 elif submit_type == 'login':
948 d = self.asyncBridgeCall("getNewAccountDomain") 951 d = self.asyncBridgeCall("getNewAccountDomain")
949 d.addCallback(lambda domain: self._loginAccount(request, domain)) 952 d.addCallback(lambda domain: self._loginAccount(request, domain))
950 return server.NOT_DONE_YET 953 return server.NOT_DONE_YET
994 997
995 try: 998 try:
996 profile = self.sat_host.bridge.getProfileName(login) 999 profile = self.sat_host.bridge.getProfileName(login)
997 except Exception: # XXX: ProfileUnknownError wouldn't work, it's encapsulated 1000 except Exception: # XXX: ProfileUnknownError wouldn't work, it's encapsulated
998 if login_jid is not None and login_jid.user: # try to create a new sat profile using the XMPP credentials 1001 if login_jid is not None and login_jid.user: # try to create a new sat profile using the XMPP credentials
1002 if not self.sat_host.options["allow_registration"]:
1003 log.warning(u"Trying to register JID account while registration is not allowed")
1004 request.write(C.PROFILE_AUTH_ERROR)
1005 request.finish()
1006 return
999 profile = login # FIXME: what if there is a resource? 1007 profile = login # FIXME: what if there is a resource?
1000 connect_method = "asyncConnectWithXMPPCredentials" 1008 connect_method = "asyncConnectWithXMPPCredentials"
1001 register_with_ext_jid = True 1009 register_with_ext_jid = True
1002 else: # non existing username 1010 else: # non existing username
1003 request.write(C.PROFILE_AUTH_ERROR) 1011 request.write(C.PROFILE_AUTH_ERROR)
1138 1146
1139 @return (dict): metadata which can have the following keys: 1147 @return (dict): metadata which can have the following keys:
1140 "plugged" (bool): True if a profile is already plugged 1148 "plugged" (bool): True if a profile is already plugged
1141 "warning" (unicode): a security warning message if plugged is False and if it make sense 1149 "warning" (unicode): a security warning message if plugged is False and if it make sense
1142 this key may not be present 1150 this key may not be present
1151 "allow_registration" (bool): True if registration is allowed
1152 this key is only present if profile is unplugged
1143 @return: a couple (registered, message) with: 1153 @return: a couple (registered, message) with:
1144 - registered: 1154 - registered:
1145 - message: 1155 - message:
1146 """ 1156 """
1147 metadata = {} 1157 metadata = {}
1150 if profile: 1160 if profile:
1151 metadata["plugged"] = True 1161 metadata["plugged"] = True
1152 else: 1162 else:
1153 metadata["plugged"] = False 1163 metadata["plugged"] = False
1154 metadata["warning"] = self._getSecurityWarning() 1164 metadata["warning"] = self._getSecurityWarning()
1165 metadata["allow_registration"] = self.sat_host.options["allow_registration"]
1155 return metadata 1166 return metadata
1156 1167
1157 def jsonrpc_registerParams(self): 1168 def jsonrpc_registerParams(self):
1158 """Register the frontend specific parameters""" 1169 """Register the frontend specific parameters"""
1159 # params = """<params><individual>...</category></individual>""" 1170 # params = """<params><individual>...</category></individual>"""