diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 444882a13..e82732359 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -6,6 +6,8 @@ - #628 Fixes the bug in displaying chat status during private chat. [saganshul] - #628 Changes the message displayed while typing from a different resource of the same user. [smitbose] - #675 Time format made configurable. [smitbose] +- #704 Automatic fetching of registration form when [registration_domain](https://conversejs.org/ +docs/html/configurations.html#registration-domain) is set. [smitbose] - #806 The `_converse.listen` API event listeners aren't triggered. [jcbrand] - #807 Error: Plugin "converse-dragresize" tried to override HeadlinesBoxView but it's not found. [jcbrand] - #820 Inconsistency in displaying room features. [jcbrand] diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 4d6af589e..c12f22c9f 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -483,6 +483,14 @@ JIDs with other domains are still allowed but need to be provided in full. To specify only one domain and disallow other domains, see the `locked_domain`_ option. +registration_domain +------------------- + +* Default: ``''`` + +Specify a domain name for which the registration form will be fetched automatically, +without the user having to enter any XMPP server domain name. + default_state ------------- diff --git a/src/converse-core.js b/src/converse-core.js index 01773866b..4a6a4083f 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -256,6 +256,7 @@ password: undefined, prebind_url: null, priority: 0, + registration_domain: '', rid: undefined, roster_groups: true, show_only_online_users: false, diff --git a/src/converse-register.js b/src/converse-register.js index a1d97a66e..73f79f729 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -72,6 +72,11 @@ 'model': this }); this.registerpanel.render().$el.addClass('hidden'); + + if (_converse.registration_domain) { + this.registerpanel.renderRegistrationRequest(''); + this.registerpanel.fetchRegistrationForm(_converse.registration_domain); + } } return this; } @@ -116,6 +121,7 @@ render: function () { this.$parent.append(this.$el.html( tpl_register_panel({ + 'default_domain': _converse.registration_domain, 'label_domain': __("Your XMPP provider's domain name:"), 'label_register': __('Fetch registration form'), 'help_providers': __('Tip: A list of public XMPP providers is available'), @@ -227,18 +233,36 @@ $domain_input.addClass('error'); return; } - $form.find('input[type=submit]').hide() - .after(tpl_registration_request({ - cancel: __('Cancel'), - info_message: __('Requesting a registration form from the XMPP server') - })); - $form.find('button.button-cancel').on('click', this.cancelRegistration.bind(this)); + $form.find('input[type=submit]').hide(); + this.renderRegistrationRequest(__('Cancel')); + this.fetchRegistrationForm(domain); + }, + + fetchRegistrationForm: function(domain_name) { + /* This is called with a domain name based on which, it fetches a + * registration form from the requested domain. + * + * Parameters: + * (Domain name) domain_name - XMPP server domain + */ this.reset({ - domain: Strophe.getDomainFromJid(domain), + domain: Strophe.getDomainFromJid(domain_name), _registering: true }); _converse.connection.connect(this.domain, "", this.onRegistering.bind(this)); - return false; + return false; + }, + + renderRegistrationRequest: function(cancel_label) { + var form_help = document.querySelector('.form-help'); + $(form_help).after(tpl_registration_request({ + cancel: cancel_label, + info_message: _converse.__('Requesting a registration form from the XMPP server') + })); + if (!_converse.registration_domain) { + var cancel_button = document.querySelector('button.button-cancel'); + cancel_button.addEventListener('click', this.cancelRegistration.bind(this)); + } }, giveFeedback: function (message, klass) { @@ -349,6 +373,9 @@ $form.append(''); $form.find('input[type=button]').on('click', this.cancelRegistration.bind(this)); } + if (_converse.registration_domain) { + $form.find('input[type=button]').hide(); + } }, reportErrors: function (stanza) { @@ -390,6 +417,11 @@ if (ev && ev.preventDefault) { ev.preventDefault(); } _converse.connection.reset(); this.render(); + if (_converse.registration_domain) { + this.renderRegistrationRequest(__('Retry')); + document.querySelector('button.button-cancel').onclick = + _.bind(this.fetchRegistrationForm, this, _converse.registration_domain); + } }, submitRegistrationForm : function (ev) { diff --git a/src/templates/register_panel.html b/src/templates/register_panel.html index 440cf61e8..81640257d 100644 --- a/src/templates/register_panel.html +++ b/src/templates/register_panel.html @@ -1,7 +1,14 @@
diff --git a/src/templates/registration_request.html b/src/templates/registration_request.html index 542b33d19..eec3dd3b7 100644 --- a/src/templates/registration_request.html +++ b/src/templates/registration_request.html @@ -1,3 +1,5 @@{{{info_message}}}
- +{[ if (cancel) { ]} + +{[ } ]}