comparison src/plugins/plugin_misc_register_account.py @ 1089:8e0072754413

core, plugins, stdui, frontends: fixes handling of "Force server" and "Force port" parameters: - do not save a "guessed" value, they must stay empty until the user explicitely sets them - add constant XMPP_C2S_PORT (default value 5222)
author souliane <souliane@mailoo.org>
date Mon, 23 Jun 2014 10:23:13 +0200
parents b29452cab50b
children 628e320eab1f
comparison
equal deleted inserted replaced
1088:b29452cab50b 1089:8e0072754413
57 session_data = {} 57 session_data = {}
58 for param in ('JabberID', 'Password', C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): 58 for param in ('JabberID', 'Password', C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
59 try: 59 try:
60 session_data[param] = data["%s%s%s%s" % (SAT_FORM_PREFIX, "Connection", SAT_PARAM_SEPARATOR, param)] 60 session_data[param] = data["%s%s%s%s" % (SAT_FORM_PREFIX, "Connection", SAT_PARAM_SEPARATOR, param)]
61 except KeyError: 61 except KeyError:
62 if param == C.FORCE_PORT_PARAM: 62 if param in (C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
63 session_data[param] = 5222 63 session_data[param] = ''
64 64
65 for param in ('JabberID', 'Password', C.FORCE_SERVER_PARAM): 65 for param in ('JabberID', 'Password'):
66 if not session_data[param]: 66 if not session_data[param]:
67 form_ui = xml_tools.XMLUI("popup", title=D_("Missing values")) 67 form_ui = xml_tools.XMLUI("popup", title=D_("Missing values"))
68 form_ui.addText(D_("No user, password or server given: can't register new account.")) 68 form_ui.addText(D_("No user JID or password given: can't register new account."))
69 return {'xmlui': form_ui.toXml()} 69 return {'xmlui': form_ui.toXml()}
70 70
71 user = jid.parse(session_data['JabberID'])[0] 71 session_data['user'], host, resource = jid.parse(session_data['JabberID'])
72 session_data['server'] = session_data[C.FORCE_SERVER_PARAM] or host
72 session_id, dummy = self._sessions.newSession(session_data, profile) 73 session_id, dummy = self._sessions.newSession(session_data, profile)
73 form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id) 74 form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id)
74 form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': user, 'server': session_data[C.FORCE_SERVER_PARAM]}) 75 form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': session_data['user'], 'server': session_data['server']})
75 return {'xmlui': form_ui.toXml()} 76 return {'xmlui': form_ui.toXml()}
76 77
77 def _registerConfirmation(self, data, profile): 78 def _registerConfirmation(self, data, profile):
78 """Save the related parameters and proceed the registration.""" 79 """Save the related parameters and proceed the registration."""
79 session_data = self._sessions.profileGet(data['session_id'], profile) 80 session_data = self._sessions.profileGet(data['session_id'], profile)
81 self.host.memory.setParam("JabberID", session_data["JabberID"], "Connection", profile_key=profile) 82 self.host.memory.setParam("JabberID", session_data["JabberID"], "Connection", profile_key=profile)
82 self.host.memory.setParam("Password", session_data["Password"], "Connection", profile_key=profile) 83 self.host.memory.setParam("Password", session_data["Password"], "Connection", profile_key=profile)
83 self.host.memory.setParam(C.FORCE_SERVER_PARAM, session_data[C.FORCE_SERVER_PARAM], "Connection", profile_key=profile) 84 self.host.memory.setParam(C.FORCE_SERVER_PARAM, session_data[C.FORCE_SERVER_PARAM], "Connection", profile_key=profile)
84 self.host.memory.setParam(C.FORCE_PORT_PARAM, session_data[C.FORCE_PORT_PARAM], "Connection", profile_key=profile) 85 self.host.memory.setParam(C.FORCE_PORT_PARAM, session_data[C.FORCE_PORT_PARAM], "Connection", profile_key=profile)
85 86
86 user = jid.parse(session_data['JabberID'])[0] 87 d = self._registerNewAccount(session_data['user'], session_data["Password"], None, session_data['server'], profile_key=profile)
87 d = self._registerNewAccount(user, session_data["Password"], None, session_data[C.FORCE_SERVER_PARAM], profile_key=profile)
88 del self._sessions[data['session_id']] 88 del self._sessions[data['session_id']]
89 return d 89 return d
90 90
91 def _registerNewAccount(self, user, password, email, host, port=5222, profile_key=C.PROF_KEY_NONE): 91 def _registerNewAccount(self, user, password, email, host, port=C.XMPP_C2S_PORT, profile_key=C.PROF_KEY_NONE):
92 """Connect to a server and create a new account using in-band registration. 92 """Connect to a server and create a new account using in-band registration.
93 @param user: login of the account 93 @param user: login of the account
94 @param password: password of the account 94 @param password: password of the account
95 @param email: email of the account 95 @param email: email of the account
96 @param host: host of the server to register to 96 @param host: host of the server to register to
99 """ 99 """
100 profile = self.host.memory.getProfileName(profile_key) 100 profile = self.host.memory.getProfileName(profile_key)
101 101
102 d = defer.Deferred() 102 d = defer.Deferred()
103 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, host, user, password, email, d, profile)) 103 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, host, user, password, email, d, profile))
104 connector = reactor.connectTCP(host, port, serverRegistrer) 104 connector = reactor.connectTCP(host, port or C.XMPP_C2S_PORT, serverRegistrer)
105 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() 105 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
106 106
107 def cb(dummy): 107 def cb(dummy):
108 xmlui = xml_tools.XMLUI("popup", title=D_("Confirmation")) 108 xmlui = xml_tools.XMLUI("popup", title=D_("Confirmation"))
109 xmlui.addText(D_("Registration successful.")) 109 xmlui.addText(D_("Registration successful."))