2
0
Эх сурвалжийг харах

Implemented auto fetching of registration form for default XMPP domain (#812)

Soumit Bose 8 жил өмнө
parent
commit
e6f3406977

+ 2 - 0
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]

+ 8 - 0
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
 -------------
 

+ 1 - 0
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,

+ 40 - 8
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('<input type="button" class="submit" value="'+__('Return')+'"/>');
                         $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) {

+ 9 - 2
src/templates/register_panel.html

@@ -1,7 +1,14 @@
 <form id="converse-register" class="pure-form converse-form">
     <span class="reg-feedback"></span>
     <label>{{{label_domain}}}</label>
-    <input type="text" name="domain" placeholder="{{{domain_placeholder}}}">
+    {[ if (default_domain) { ]}
+    	<label>{{{default_domain}}}</label>
+    {[ } ]}
+    {[ if (!default_domain) { ]}
+    	<input type="text" name="domain" placeholder="{{{domain_placeholder}}}">
+    {[ } ]}
     <p class="form-help">{{{help_providers}}} <a href="{{{href_providers}}}" class="url" target="_blank" rel="noopener">{{{help_providers_link}}}</a>.</p>
-    <input class="pure-button button-primary" type="submit" value="{{{label_register}}}">
+    {[ if (!default_domain) { ]}
+    	<input class="pure-button button-primary" type="submit" value="{{{label_register}}}">
+    {[ } ]}
 </form>

+ 3 - 1
src/templates/registration_request.html

@@ -1,3 +1,5 @@
 <span class="spinner login-submit"/>
 <p class="info">{{{info_message}}}</p>
-<button class="pure-button button-cancel hor_centered">{{{cancel}}}</button>
+{[ if (cancel) { ]}
+	<button class="pure-button button-cancel hor_centered">{{{cancel}}}</button>
+{[ } ]}