plugin XEP-0077: added changePassword and removeRegistration methods
This commit is contained in:
parent
03d8930672
commit
1c64f98989
2 changed files with 28 additions and 13 deletions
|
|
@ -80,7 +80,6 @@ class RegisterAccount(object):
|
|||
|
||||
def _registerConfirmation(self, data, profile):
|
||||
"""Save the related parameters and proceed the registration."""
|
||||
client = self.host.getClient(profile)
|
||||
session_data = self._sessions.profileGet(data['session_id'], profile)
|
||||
|
||||
self.host.memory.setParam("JabberID", session_data["JabberID"], "Connection", profile_key=profile)
|
||||
|
|
@ -88,7 +87,7 @@ class RegisterAccount(object):
|
|||
self.host.memory.setParam(C.FORCE_SERVER_PARAM, session_data[C.FORCE_SERVER_PARAM], "Connection", profile_key=profile)
|
||||
self.host.memory.setParam(C.FORCE_PORT_PARAM, session_data[C.FORCE_PORT_PARAM], "Connection", profile_key=profile)
|
||||
|
||||
d = self._registerNewAccount(client, jid.JID(session_data['JabberID']), session_data["Password"], None, session_data['server'])
|
||||
d = self._registerNewAccount(jid.JID(session_data['JabberID']), session_data["Password"], None, session_data['server'])
|
||||
del self._sessions[data['session_id']]
|
||||
return d
|
||||
|
||||
|
|
|
|||
|
|
@ -62,16 +62,7 @@ class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
|
|||
self.xmlstream.namespace = C.NS_CLIENT
|
||||
self.xmlstream.sendHeader()
|
||||
|
||||
iq = xmlstream.IQ(self.xmlstream, 'set')
|
||||
iq["to"] = self.jid.host
|
||||
query_elt = iq.addElement(('jabber:iq:register', 'query'))
|
||||
username_elt = query_elt.addElement('username')
|
||||
username_elt.addContent(self.jid.user)
|
||||
password_elt = query_elt.addElement('password')
|
||||
password_elt.addContent(self.password)
|
||||
if self.email is not None:
|
||||
email_elt = query_elt.addElement('email')
|
||||
email_elt.addContent(self.email)
|
||||
iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email)
|
||||
d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb)
|
||||
d.chainDeferred(self.registered)
|
||||
|
||||
|
|
@ -94,6 +85,20 @@ class XEP_0077(object):
|
|||
method=self._inBandRegister,
|
||||
async=True)
|
||||
|
||||
@staticmethod
|
||||
def buildRegisterIQ(xmlstream_, jid_, password, email=None):
|
||||
iq_elt = xmlstream.IQ(xmlstream_, 'set')
|
||||
iq_elt["to"] = jid_.host
|
||||
query_elt = iq_elt.addElement(('jabber:iq:register', 'query'))
|
||||
username_elt = query_elt.addElement('username')
|
||||
username_elt.addContent(jid_.user)
|
||||
password_elt = query_elt.addElement('password')
|
||||
password_elt.addContent(password)
|
||||
if email is not None:
|
||||
email_elt = query_elt.addElement('email')
|
||||
email_elt.addContent(email)
|
||||
return iq_elt
|
||||
|
||||
def _regCb(self, answer, client, post_treat_cb):
|
||||
"""Called after the first get IQ"""
|
||||
try:
|
||||
|
|
@ -156,7 +161,7 @@ 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, client, jid_, password, email=None, host="127.0.0.1", port=C.XMPP_C2S_PORT):
|
||||
def registerNewAccount(self, jid_, password, email=None, host="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
|
||||
|
|
@ -171,3 +176,14 @@ class XEP_0077(object):
|
|||
connector = reactor.connectTCP(host, port, serverRegistrer)
|
||||
serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
|
||||
return registered_d
|
||||
|
||||
def changePassword(self, client, new_password):
|
||||
iq_elt = self.buildRegisterIQ(client.xmlstream, client.jid, new_password)
|
||||
return iq_elt.send(client.jid.host)
|
||||
|
||||
def removeRegistration(self, client, to_jid):
|
||||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue