Commit 86164a02 authored by Philipp Hörist's avatar Philipp Hörist

Register: Use nbxmpp methods

parent 5ac5439d
Pipeline #5232 passed with stages
in 3 minutes and 5 seconds
......@@ -28,6 +28,8 @@ class Register(BaseModule):
_nbxmpp_extends = 'Register'
_nbxmpp_methods = [
'unregister',
'change_password',
'change_password_with_form',
]
def __init__(self, con):
......@@ -35,35 +37,6 @@ class Register(BaseModule):
self.agent_registrations = {}
def change_password(self, password, success_cb, error_cb):
if not app.account_is_connected(self._account):
return
hostname = app.config.get_per('accounts', self._account, 'hostname')
username = app.config.get_per('accounts', self._account, 'name')
iq = nbxmpp.Iq(typ='set', to=hostname)
query = iq.setTag(nbxmpp.NS_REGISTER + ' query')
query.setTagData('username', username)
query.setTagData('password', password)
weak_success_cb = weakref.WeakMethod(success_cb)
weak_error_cb = weakref.WeakMethod(error_cb)
self._log.info('Send password change')
self._con.connection.SendAndCallForResponse(
iq, self._change_password_response, {'success_cb': weak_success_cb,
'error_cb': weak_error_cb})
def _change_password_response(self, _nbxmpp_client, stanza,
success_cb, error_cb):
if not nbxmpp.isResultNode(stanza):
error = stanza.getErrorMsg()
self._log.info('Error: %s', error)
if error_cb() is not None:
error_cb()(error)
else:
self._log.info('Password changed')
if success_cb() is not None:
success_cb()()
def register_agent(self, agent, form, is_form, success_cb, error_cb):
if not app.account_is_connected(self._account):
return
......
......@@ -110,15 +110,14 @@ class ChangePassword(Assistant):
self.set_default_button('back')
def _on_apply(self, next_stage=False):
register = self._con.connection.get_module('Register')
if next_stage:
form = self.get_page('next_stage').get_submit_form()
register.change_password_with_form(
self._con.get_module('Register').change_password_with_form(
form, callback=self._on_change_password)
else:
password = self.get_page('password').get_password()
register.change_password(password,
callback=self._on_change_password)
self._con.get_module('Register').change_password(
password, callback=self._on_change_password)
@ensure_not_destroyed
def _on_change_password(self, result):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment