plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
This commit is contained in:
parent
06be5a58aa
commit
7c58313ed0
1 changed files with 46 additions and 7 deletions
|
|
@ -81,9 +81,18 @@ class XEP_0077(object):
|
|||
def __init__(self, host):
|
||||
log.info(_("Plugin XEP_0077 initialization"))
|
||||
self.host = host
|
||||
host.bridge.addMethod("inBandRegister", ".plugin", in_sign='ss', out_sign='s',
|
||||
host.bridge.addMethod("inBandRegister", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self._inBandRegister,
|
||||
async=True)
|
||||
host.bridge.addMethod("inBandAccountNew", ".plugin", in_sign='ssssi', out_sign='',
|
||||
method=self._registerNewAccount,
|
||||
async=True)
|
||||
host.bridge.addMethod("inBandUnregister", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self._unregister,
|
||||
async=True)
|
||||
host.bridge.addMethod("inBandPasswordChange", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self._changePassword,
|
||||
async=True)
|
||||
|
||||
@staticmethod
|
||||
def buildRegisterIQ(xmlstream_, jid_, password, email=None):
|
||||
|
|
@ -151,7 +160,11 @@ class XEP_0077(object):
|
|||
return self.inBandRegister, jid.JID(to_jid_s, profile_key)
|
||||
|
||||
def inBandRegister(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""register to a target JID"""
|
||||
"""register to a service
|
||||
|
||||
@param to_jid(jid.JID): jid of the service to register to
|
||||
"""
|
||||
# FIXME: this post_treat_cb arguments seems wrong, check it
|
||||
client = self.host.getClient(profile_key)
|
||||
log.debug(_(u"Asking registration for {}").format(to_jid.full()))
|
||||
reg_request = client.IQ(u'get')
|
||||
|
|
@ -161,7 +174,17 @@ class XEP_0077(object):
|
|||
d = reg_request.send(to_jid.full()).addCallbacks(self._regCb, self._regEb, callbackArgs=[client, post_treat_cb], errbackArgs=[client])
|
||||
return d
|
||||
|
||||
def registerNewAccount(self, jid_, password, email=None, host="127.0.0.1", port=C.XMPP_C2S_PORT):
|
||||
def _registerNewAccount(self, jid_, password, email, host, port):
|
||||
kwargs = {}
|
||||
if email:
|
||||
kwargs['email'] = email
|
||||
if host:
|
||||
kwargs['host'] = host
|
||||
if port:
|
||||
kwargs['port'] = port
|
||||
return self.registerNewAccount(jid.JID(jid_), password, **kwargs)
|
||||
|
||||
def registerNewAccount(self, jid_, password, email=None, host=u"127.0.0.1", port=C.XMPP_C2S_PORT):
|
||||
"""register a new account on a XMPP server
|
||||
|
||||
@param jid_(jid.JID): request jid to register
|
||||
|
|
@ -177,13 +200,29 @@ class XEP_0077(object):
|
|||
serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
|
||||
return registered_d
|
||||
|
||||
def _changePassword(self, new_password, profile_key):
|
||||
client = self.host.getClient(profile_key)
|
||||
return self.changePassword(client, new_password)
|
||||
|
||||
def changePassword(self, client, new_password):
|
||||
iq_elt = self.buildRegisterIQ(client.xmlstream, client.jid, new_password)
|
||||
return iq_elt.send(client.jid.host)
|
||||
d = iq_elt.send(client.jid.host)
|
||||
d.addCallback(lambda dummy: self.host.memory.setParam("Password", new_password, "Connection", profile_key=client.profile))
|
||||
return d
|
||||
|
||||
def removeRegistration(self, client, to_jid):
|
||||
def _unregister(self, to_jid_s, profile_key):
|
||||
client = self.host.getClient(profile_key)
|
||||
return self.unregister(client, jid.JID(to_jid_s))
|
||||
|
||||
def unregister(self, client, to_jid):
|
||||
"""remove registration from a server/service
|
||||
|
||||
BEWARE! if you remove registration from profile own server, this will
|
||||
DELETE THE XMPP ACCOUNT WITHOUT WARNING
|
||||
@param to_jid(jid.JID): jid of the service or server
|
||||
"""
|
||||
iq_elt = client.IQ()
|
||||
iq_elt['to'] = to_jid.full()
|
||||
query_elt = iq_elt.addElement((NS_REG, u'query'))
|
||||
query_elt.addElement(u'remove')
|
||||
iq_elt.send()
|
||||
return iq_elt.send()
|
||||
|
|
|
|||
Loading…
Reference in a new issue