def save_account(self, login, server, savepass, password, anonymous=False): if self.account in app.connections: ErrorDialog(_('Account name is in use'), _('You already have an account using this name.')) return con = connection.Connection(self.account) con.password = password config = self.get_config(login, server, savepass, password, anonymous) if not self.modify: con.new_account(self.account, config) return app.connections[self.account] = con self.create_vars(config)
def on_forward_button_clicked(self, widget): cur_page = self.notebook.get_current_page() if cur_page == 0: widget = self.xml.get_object('use_existing_account_radiobutton') if widget.get_active(): self.modify = True self.notebook.set_current_page(1) else: self.modify = False self.notebook.set_current_page(2) self.back_button.set_sensitive(True) return if cur_page == 1: # We are adding an existing account anonymous = self.xml.get_object('anonymous_checkbutton1').\ get_active() username = self.xml.get_object('username_entry').get_text().strip() if not username and not anonymous: pritext = _('Invalid username') sectext = _( 'You must provide a username to configure this account.') ErrorDialog(pritext, sectext) return server = self.xml.get_object('server_comboboxtext_entry').\ get_text().strip() savepass = self.xml.get_object('save_password_checkbutton').\ get_active() password = self.xml.get_object('password_entry').get_text() if anonymous: jid = '' else: jid = username + '@' jid += server # check if jid is conform to RFC and stringprep it try: jid = helpers.parse_jid(jid) except helpers.InvalidFormat as s: pritext = _('Invalid XMPP Address') ErrorDialog(pritext, str(s)) return self.account = server i = 1 while self.account in app.config.get_per('accounts'): self.account = server + str(i) i += 1 username, server = app.get_name_and_server_from_jid(jid) if self.xml.get_object('anonymous_checkbutton1').get_active(): self.save_account('', server, False, '', anonymous=True) else: self.save_account(username, server, savepass, password) self.show_finish_page() elif cur_page == 2: # We are creating a new account server = self.xml.get_object('server_comboboxtext_entry1').\ get_text() if not server: ErrorDialog( _('Invalid server'), _('Please provide a server on which you want to register.')) return self.account = server i = 1 while self.account in app.config.get_per('accounts'): self.account = server + str(i) i += 1 config = self.get_config('', server, '', '') # Get advanced options proxies_combobox = self.xml.get_object('proxies_combobox') active = proxies_combobox.get_active() proxy = proxies_combobox.get_model()[active][0] if proxy == _('None'): proxy = '' config['proxy'] = proxy config['use_custom_host'] = self.xml.get_object( 'custom_host_port_checkbutton').get_active() custom_port = self.xml.get_object('custom_port_entry').get_text() try: custom_port = int(custom_port) except Exception: ErrorDialog( _('Invalid entry'), _('Custom port must be a port number.')) return config['custom_port'] = custom_port config['custom_host'] = self.xml.get_object( 'custom_host_entry').get_text() if self.xml.get_object('anonymous_checkbutton2').get_active(): self.modify = True self.save_account('', server, False, '', anonymous=True) self.show_finish_page() else: self.notebook.set_current_page(5) # show creating page self.back_button.hide() self.forward_button.hide() self.update_progressbar_timeout_id = GLib.timeout_add( 100, self.update_progressbar) # Get form from serveur con = connection.Connection(self.account) app.connections[self.account] = con con.new_account(self.account, config) elif cur_page == 3: checked = self.xml.get_object('ssl_checkbutton').get_active() if checked: hostname = app.connections[self.account].new_account_info[ 'hostname'] # Check if cert is already in file certs = '' my_ca_certs = configpaths.get('MY_CACERTS') if os.path.isfile(my_ca_certs): with open(my_ca_certs) as f: certs = f.read() if self.ssl_cert in certs: ErrorDialog( _('Certificate Already in File'), _('This certificate is already in file %s, so it\'s ' 'not added again.') % my_ca_certs) else: with open(my_ca_certs, 'a') as f: f.write(hostname + '\n') f.write(self.ssl_cert + '\n\n') app.connections[self.account].new_account_info[ 'ssl_fingerprint_sha1'] = self.ssl_fingerprint_sha1 app.connections[self.account].new_account_info[ 'ssl_fingerprint_sha256'] = self.ssl_fingerprint_sha256 self.notebook.set_current_page(4) # show fom page elif cur_page == 4: if self.is_form: form = self.data_form_widget.data_form else: form = self.data_form_widget.get_submit_form() app.connections[self.account].send_new_account_infos( form, self.is_form) self.xml.get_object('form_vbox').remove(self.data_form_widget) self.xml.get_object('progressbar_label').set_markup( '<b>Account is being created</b>\n\nPlease wait…') self.notebook.set_current_page(5) # show creating page self.back_button.hide() self.forward_button.hide() self.update_progressbar_timeout_id = GLib.timeout_add( 100, self.update_progressbar)