Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Leboulanger <asterix@lagaule.org>2007-12-03 01:37:08 +0300
committerYann Leboulanger <asterix@lagaule.org>2007-12-03 01:37:08 +0300
commit31a1f3ef6dfdcfa907245e30a6ca873c5a8d3685 (patch)
tree92ac26a9c22b3df373588cc454b46bb680b43aee
parent157d6826ec14b8d9a0dfb700dbb8705967a2b295 (diff)
create new account in 2 steps:
1/ connect, get form and disconnect 2/ re-connect, get form, check it and send filled form
-rw-r--r--src/common/connection.py65
-rw-r--r--src/config.py3
2 files changed, 47 insertions, 21 deletions
diff --git a/src/common/connection.py b/src/common/connection.py
index aeeae5ee6..99c78654e 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -119,6 +119,7 @@ class Connection(ConnectionHandlers):
self.time_to_reconnect = None
self.last_time_to_reconnect = None
self.new_account_info = None
+ self.new_account_form = None
self.bookmarks = []
self.annotations = {}
self.on_purpose = False
@@ -184,7 +185,7 @@ class Connection(ConnectionHandlers):
self.retrycount = 0
# We are doing disconnect at so many places, better use one function in all
- def disconnect(self, on_purpose = False):
+ def disconnect(self, on_purpose=False):
self.on_purpose = on_purpose
self.connected = 0
self.time_to_reconnect = None
@@ -259,8 +260,47 @@ class Connection(ConnectionHandlers):
return
is_form = data[2]
conf = data[1]
- self.dispatch('NEW_ACC_CONNECTED', (conf, is_form))
- return
+ if self.new_account_form:
+ def _on_register_result(result):
+ if not common.xmpp.isResultNode(result):
+ self.dispatch('ACC_NOT_OK', (result.getError()))
+ return
+ if USE_GPG:
+ self.gpg = GnuPG.GnuPG(gajim.config.get(
+ 'use_gpg_agent'))
+ self.dispatch('ACC_OK', (self.new_account_info))
+ self.new_account_info = None
+ self.new_account_form = None
+ if self.connection:
+ self.connection.UnregisterDisconnectHandler(
+ self._on_new_account)
+ self.disconnect(on_purpose=True)
+ # it's the second time we get the form, we have info user
+ # typed, so send them
+ if is_form:
+ #TODO: Check if form has changed
+ iq = Iq('set', NS_REGISTER, to=self._hostname)
+ iq.setTag('query').addChild(node=self.new_account_form)
+ self.connection.SendAndCallForResponse(iq,
+ _on_register_result)
+ else:
+ if self.new_account_form.keys().sort() != \
+ conf.keys().sort():
+ # requested config has changed since first connection
+ self.dispatch('ACC_NOT_OK', (_(
+ 'Server %s provided a different registration form')\
+ % data[0]))
+ return
+ common.xmpp.features_nb.register(self.connection,
+ self._hostname, self.new_account_form,
+ _on_register_result)
+ return
+ else:
+ self.dispatch('NEW_ACC_CONNECTED', (conf, is_form))
+ self.connection.UnregisterDisconnectHandler(
+ self._on_new_account)
+ self.disconnect(on_purpose=True)
+ return
if not data[1]: # wrong answer
self.dispatch('ERROR', (_('Invalid answer'),
_('Transport %s answered wrongly to register request: %s') % \
@@ -1029,18 +1069,6 @@ class Connection(ConnectionHandlers):
groups = groups)
def send_new_account_infos(self, form, is_form):
- def _on_register_result(result):
- if not common.xmpp.isResultNode(result):
- self.dispatch('ACC_NOT_OK', (result.getError()))
- return
- if USE_GPG:
- self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
- gajim.connections[self.name] = self
- self.dispatch('ACC_OK', (self.new_account_info))
- self.new_account_info = None
- if self.connection:
- self.connection.UnregisterDisconnectHandler(self._on_new_account)
- self.disconnect(on_purpose=True)
if is_form:
# Get username and password and put them in new_account_info
for field in self._data_form.iter_fields():
@@ -1048,17 +1076,14 @@ class Connection(ConnectionHandlers):
self.new_account_info['name'] = field.value
if field.var == 'password':
self.new_account_info['password'] = field.value
- iq=Iq('set', NS_REGISTER, to = self._hostname)
- iq.setTag('query').addChild(node = form)
- self.connection.SendAndCallForResponse(iq, _on_register_result)
else:
# Get username and password and put them in new_account_info
if form.has_key('username'):
self.new_account_info['name'] = form['username']
if form.has_key('password'):
self.new_account_info['password'] = form['password']
- common.xmpp.features_nb.register(self.connection, self._hostname,
- form, _on_register_result)
+ self.new_account_form = form
+ self.new_account(self.name, self.new_account_info)
def new_account(self, name, config, sync = False):
# If a connection already exist we cannot create a new account
diff --git a/src/config.py b/src/config.py
index 43b8979d4..0b673337c 100644
--- a/src/config.py
+++ b/src/config.py
@@ -3088,6 +3088,7 @@ class AccountCreationWizardWindow:
self.notebook.set_current_page(5) # show finish page
self.show_vcard_checkbutton.set_active(False)
elif cur_page == 2:
+ # We are creating a new account
server = self.xml.get_widget('server_comboboxentry1').child.get_text()\
.decode('utf-8')
@@ -3172,7 +3173,7 @@ class AccountCreationWizardWindow:
return True # loop forever
def new_acc_connected(self, form, is_form):
- '''connection to server succeded, present the form to the user'''
+ '''connection to server succeded, present the form to the user.'''
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
self.back_button.show()