core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:

- the bridge method has been removed, now a plugin takes care of it with XMLUI callback system
    - TODO: xmpp.RegisteringAuthenticator still needs to be fixed
This commit is contained in:
souliane 2014-05-16 00:58:20 +02:00
commit dd597a2ead

View file

@ -20,7 +20,7 @@
from sat.core.i18n import _, languageSwitch
from twisted.application import service
from twisted.internet import defer
from twisted.words.protocols.jabber import jid, xmlstream
from twisted.words.protocols.jabber import jid
from twisted.words.xish import domish
from twisted.internet import reactor
from wokkel.xmppim import RosterItem
@ -102,7 +102,6 @@ class SAT(service.Service):
self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile)
self.bridge.register("registerNewAccount", self.registerNewAccount)
self.bridge.register("connect", self.connect)
self.bridge.register("asyncConnect", self.asyncConnect)
self.bridge.register("disconnect", self.disconnect)
@ -413,52 +412,6 @@ class SAT(service.Service):
raise exceptions.ProfileKeyUnknownError
return [self.profiles[profile]]
def registerNewAccount(self, login, password, email, server, port=5222, id_=None, profile_key=C.PROF_KEY_NONE):
"""Connect to a server and create a new account using in-band registration"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
next_id = id_ or self.get_next_id() # the id is used to send server's answer
serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id, profile))
connector = reactor.connectTCP(server, port, serverRegistrer)
serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
return next_id
def registerNewAccountCB(self, data, profile):
# FIXME: to be removed/redone elsewhere
user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
server = self.memory.getParamA("Server", "Connection", profile_key=profile)
d = self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
def gotPassword(password):
if not user or not password or not server:
raise exceptions.DataError(_("No user, password or server given, can't register new account."))
# FIXME: to be fixed with XMLUI dialogs once their implemented
confirm_id = sat_next_id()
self.__private_data[confirm_id] = (id, profile)
self.askConfirmation(
confirm_id, "YES/NO",
{"message": _("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user': user, 'server': server, 'profile': profile}},
self.regisConfirmCB, profile)
print "===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============"
d.addCallback(gotPassword)
def regisConfirmCB(self, id, accepted, data, profile):
print _("register Confirmation CB ! (%s)") % str(accepted)
action_id, profile = self.__private_data[id]
del self.__private_data[id]
if accepted:
user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
server = self.memory.getParamA("Server", "Connection", profile_key=profile)
d = self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
d.addCallback(lambda password: self.registerNewAccount(user, password, None, server, id=action_id))
else:
self.actionResult(action_id, "SUPPRESS", {}, profile)
## Client management ##
def setParam(self, name, value, category, security_limit, profile_key):