Mercurial > libervia-backend
comparison src/core/sat_main.py @ 1037:6e975c6b0faf
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
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 16 May 2014 00:58:20 +0200 |
parents | b262ae6d53af |
children | 066308706dc6 |
comparison
equal
deleted
inserted
replaced
1036:35048cafb18d | 1037:6e975c6b0faf |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _, languageSwitch | 20 from sat.core.i18n import _, languageSwitch |
21 from twisted.application import service | 21 from twisted.application import service |
22 from twisted.internet import defer | 22 from twisted.internet import defer |
23 from twisted.words.protocols.jabber import jid, xmlstream | 23 from twisted.words.protocols.jabber import jid |
24 from twisted.words.xish import domish | 24 from twisted.words.xish import domish |
25 from twisted.internet import reactor | 25 from twisted.internet import reactor |
26 from wokkel.xmppim import RosterItem | 26 from wokkel.xmppim import RosterItem |
27 from sat.bridge.DBus import DBusBridge | 27 from sat.bridge.DBus import DBusBridge |
28 from sat.core import xmpp | 28 from sat.core import xmpp |
100 self.bridge.register("getProfileName", self.memory.getProfileName) | 100 self.bridge.register("getProfileName", self.memory.getProfileName) |
101 self.bridge.register("getProfilesList", self.memory.getProfilesList) | 101 self.bridge.register("getProfilesList", self.memory.getProfilesList) |
102 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) | 102 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) |
103 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) | 103 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) |
104 self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile) | 104 self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile) |
105 self.bridge.register("registerNewAccount", self.registerNewAccount) | |
106 self.bridge.register("connect", self.connect) | 105 self.bridge.register("connect", self.connect) |
107 self.bridge.register("asyncConnect", self.asyncConnect) | 106 self.bridge.register("asyncConnect", self.asyncConnect) |
108 self.bridge.register("disconnect", self.disconnect) | 107 self.bridge.register("disconnect", self.disconnect) |
109 self.bridge.register("getContacts", self.getContacts) | 108 self.bridge.register("getContacts", self.getContacts) |
110 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) | 109 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) |
411 return self.profiles.values() | 410 return self.profiles.values() |
412 if profile.count('@') > 1: | 411 if profile.count('@') > 1: |
413 raise exceptions.ProfileKeyUnknownError | 412 raise exceptions.ProfileKeyUnknownError |
414 return [self.profiles[profile]] | 413 return [self.profiles[profile]] |
415 | 414 |
416 def registerNewAccount(self, login, password, email, server, port=5222, id_=None, profile_key=C.PROF_KEY_NONE): | |
417 """Connect to a server and create a new account using in-band registration""" | |
418 profile = self.memory.getProfileName(profile_key) | |
419 assert(profile) | |
420 | |
421 next_id = id_ or self.get_next_id() # the id is used to send server's answer | |
422 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id, profile)) | |
423 connector = reactor.connectTCP(server, port, serverRegistrer) | |
424 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() | |
425 | |
426 return next_id | |
427 | |
428 def registerNewAccountCB(self, data, profile): | |
429 # FIXME: to be removed/redone elsewhere | |
430 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] | |
431 server = self.memory.getParamA("Server", "Connection", profile_key=profile) | |
432 d = self.memory.asyncGetParamA("Password", "Connection", profile_key=profile) | |
433 | |
434 def gotPassword(password): | |
435 if not user or not password or not server: | |
436 raise exceptions.DataError(_("No user, password or server given, can't register new account.")) | |
437 | |
438 # FIXME: to be fixed with XMLUI dialogs once their implemented | |
439 confirm_id = sat_next_id() | |
440 self.__private_data[confirm_id] = (id, profile) | |
441 | |
442 self.askConfirmation( | |
443 confirm_id, "YES/NO", | |
444 {"message": _("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user': user, 'server': server, 'profile': profile}}, | |
445 self.regisConfirmCB, profile) | |
446 print "===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============" | |
447 | |
448 d.addCallback(gotPassword) | |
449 | |
450 def regisConfirmCB(self, id, accepted, data, profile): | |
451 print _("register Confirmation CB ! (%s)") % str(accepted) | |
452 action_id, profile = self.__private_data[id] | |
453 del self.__private_data[id] | |
454 if accepted: | |
455 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] | |
456 server = self.memory.getParamA("Server", "Connection", profile_key=profile) | |
457 d = self.memory.asyncGetParamA("Password", "Connection", profile_key=profile) | |
458 d.addCallback(lambda password: self.registerNewAccount(user, password, None, server, id=action_id)) | |
459 else: | |
460 self.actionResult(action_id, "SUPPRESS", {}, profile) | |
461 | |
462 ## Client management ## | 415 ## Client management ## |
463 | 416 |
464 def setParam(self, name, value, category, security_limit, profile_key): | 417 def setParam(self, name, value, category, security_limit, profile_key): |
465 """set wanted paramater and notice observers""" | 418 """set wanted paramater and notice observers""" |
466 self.memory.setParam(name, value, category, security_limit, profile_key) | 419 self.memory.setParam(name, value, category, security_limit, profile_key) |