comparison src/core/xmpp.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 301b342c697a
children 71d63750963e
comparison
equal deleted inserted replaced
1036:35048cafb18d 1037:6e975c6b0faf
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
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 _ 20 from sat.core.i18n import _, D_
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from twisted.internet import task, defer 22 from twisted.internet import task, defer
23 from twisted.words.protocols.jabber import jid, xmlstream 23 from twisted.words.protocols.jabber import jid, xmlstream
24 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel 24 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel
25 from sat.core.log import getLogger 25 from sat.core.log import getLogger
410 generic.FallbackHandler.iqFallback(self, iq) 410 generic.FallbackHandler.iqFallback(self, iq)
411 411
412 412
413 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): 413 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
414 414
415 def __init__(self, host, jabber_host, user_login, user_pass, email, answer_id, profile): 415 def __init__(self, host, jabber_host, user_login, user_pass, email, deferred, profile):
416 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) 416 xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
417 self.host = host 417 self.host = host
418 self.jabber_host = jabber_host 418 self.jabber_host = jabber_host
419 self.user_login = user_login 419 self.user_login = user_login
420 self.user_pass = user_pass 420 self.user_pass = user_pass
421 self.user_email = email 421 self.user_email = email
422 self.answer_id = answer_id 422 self.deferred = deferred
423 self.profile = profile 423 self.profile = profile
424 print _("Registration asked for"), user_login, user_pass, jabber_host 424 log.debug(_("Registration asked for %(user)s@%(host)s") % {'user': user_login, 'host': jabber_host})
425 425
426 def connectionMade(self): 426 def connectionMade(self):
427 print "connectionMade" 427 log.debug(_("Connection made with %s" % self.jabber_host))
428
429 self.xmlstream.namespace = "jabber:client" 428 self.xmlstream.namespace = "jabber:client"
430 self.xmlstream.sendHeader() 429 self.xmlstream.sendHeader()
431 430
432 iq = compat.IQ(self.xmlstream, 'set') 431 iq = compat.IQ(self.xmlstream, 'set')
433 iq["to"] = self.jabber_host 432 iq["to"] = self.jabber_host
437 _pass = query.addElement('password') 436 _pass = query.addElement('password')
438 _pass.addContent(self.user_pass) 437 _pass.addContent(self.user_pass)
439 if self.user_email: 438 if self.user_email:
440 _email = query.addElement('email') 439 _email = query.addElement('email')
441 _email.addContent(self.user_email) 440 _email.addContent(self.user_email)
442 iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) 441 d = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
442 d.chainDeferred(self.deferred)
443 443
444 def registrationAnswer(self, answer): 444 def registrationAnswer(self, answer):
445 log.debug(_("registration answer: %s") % answer.toXml()) 445 log.debug(_("Registration answer: %s") % answer.toXml())
446 answer_type = "SUCCESS"
447 answer_data = {"message": _("Registration successfull")}
448 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data, self.profile)
449 self.xmlstream.sendFooter() 446 self.xmlstream.sendFooter()
450 447
451 def registrationFailure(self, failure): 448 def registrationFailure(self, failure):
452 log.info(_("Registration failure: %s") % str(failure.value)) 449 log.info(_("Registration failure: %s") % str(failure.value))
453 answer_type = "ERROR"
454 answer_data = {}
455 if failure.value.condition == 'conflict':
456 answer_data['reason'] = 'conflict'
457 answer_data = {"message": _("Username already exists, please choose an other one")}
458 else:
459 answer_data['reason'] = 'unknown'
460 answer_data = {"message": _("Registration failed (%s)") % str(failure.value.condition)}
461 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data, self.profile)
462 self.xmlstream.sendFooter() 450 self.xmlstream.sendFooter()
451 raise failure.value
463 452
464 453
465 class SatVersionHandler(generic.VersionHandler): 454 class SatVersionHandler(generic.VersionHandler):
466 455
467 def getDiscoInfo(self, requestor, target, node): 456 def getDiscoInfo(self, requestor, target, node):