Commit 86c18b88 authored by Philipp Hörist's avatar Philipp Hörist

Make anonymous login work again

parent 00322c0c
Pipeline #5666 passed with stages
in 2 minutes and 53 seconds
......@@ -148,6 +148,11 @@ class Client(ConnectionHandlers):
# his password
self.password = passwords.get_password(self._account)
anonymous = app.config.get_per(
'accounts', self._account, 'anonymous_auth')
if anonymous:
self._client.set_mechs(['ANONYMOUS'])
self._client.set_password(self.password)
self._client.set_accepted_certificates(
app.cert_store.get_certificates())
......
......@@ -701,7 +701,6 @@ Creating an account on one server allows you to communicate with contacts from o
<object class="GtkCheckButton" id="sign_up_anonymously">
<property name="label" translatable="yes">Sign up Anonymously</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Note: Anonymous accounts are not possible on all servers</property>
......
......@@ -136,17 +136,29 @@ class AccountWizard(Assistant):
if self.get_page('signup').is_advanced():
self.show_page('advanced',
Gtk.StackTransitionType.SLIDE_LEFT)
elif self.get_page('signup').is_anonymous():
self._test_anonymous_server()
else:
self._register_with_server()
elif page == 'advanced':
self._register_with_server()
if self.get_page('signup').is_anonymous():
self._test_anonymous_server()
else:
self._register_with_server()
elif page == 'security-warning':
if self.get_page('security-warning').trust_certificate:
app.cert_store.add_certificate(
self.get_page('security-warning').cert)
self._register_with_server(ignore_all_errors=True)
if self.get_page('signup').is_anonymous():
self._test_anonymous_server(ignore_all_errors=True)
else:
self._register_with_server(ignore_all_errors=True)
elif page == 'form':
self._show_progress_page(_('Creating Account...'),
......@@ -155,8 +167,6 @@ class AccountWizard(Assistant):
elif button_name == 'connect':
if page == 'success':
# if self.get_page('success').is_update():
# app.interface.show_vcard_when_connect.append(self.account)
app.interface.enable_account(self.get_page('success').account)
self.destroy()
......@@ -279,6 +289,22 @@ class AccountWizard(Assistant):
self._client.connect()
def _test_anonymous_server(self, ignore_all_errors=False):
self._show_progress_page(_('Connecting...'),
_('Connecting to server...'))
domain = self.get_page('signup').get_server()
advanced = self.get_page('signup').is_advanced()
self._client = self._get_base_client(
domain,
None,
Mode.ANONYMOUS_TEST,
advanced,
ignore_all_errors)
self._client.subscribe('anonymous-supported', self._on_anonymous_supported)
self._client.connect()
def _register_with_server(self, ignore_all_errors=False):
self._show_progress_page(_('Connecting...'),
_('Connecting to server...'))
......@@ -315,12 +341,33 @@ class AccountWizard(Assistant):
client.get_module('Register').request_register_form(
callback=self._on_register_form)
def _on_anonymous_supported(self, client, _signal_name):
account = self._generate_account_name(client.domain)
proxy_name = None
if client.proxy is not None:
proxy_name = self.get_page('advanced').get_proxy()
app.interface.create_account(account,
None,
client.domain,
client.password,
proxy_name,
client.custom_host,
anonymous=True)
self.get_page('success').set_account(account)
self.show_page('success', Gtk.StackTransitionType.SLIDE_LEFT)
def _on_disconnected(self, client, _signal_name):
domain, error, text = client.get_error()
if domain == StreamError.SASL:
self._show_error_page(_('Authentication failed'),
SASL_ERRORS.get(error),
text or '')
if error == 'anonymous-not-supported':
self._show_error_page(_('Anonymous login not supported'),
_('Anonymous login not supported'),
_('This server does not support anonymous'))
else:
self._show_error_page(_('Authentication failed'),
SASL_ERRORS.get(error),
text or '')
elif domain == StreamError.BAD_CERTIFICATE:
self.get_page('security-warning').set_warning(
......
......@@ -1615,17 +1615,16 @@ class Interface:
custom_host,
anonymous=False):
if not account or not username or not domain:
log.error('Creating account failed: '
'account: %s, username: %s, domain: %s',
account, username, domain)
return
account_label = f'{username}@{domain}'
if anonymous:
username = 'anon'
account_label = f'anon@{domain}'
config = {}
config['active'] = False
config['name'] = username
config['resource'] = 'gajim.%s' % helpers.get_random_string(8)
config['account_label'] = '%s@%s' % (username, domain)
config['account_label'] = account_label
config['account_color'] = get_color_for_account(
'%s@%s' % (username, domain))
config['hostname'] = domain
......
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