Fixes #828 Add routing for login and register URL fragments

This commit is contained in:
JC Brand 2017-09-16 19:17:54 +02:00
parent 7e4fb52f8d
commit 158acbf1d7
6 changed files with 59 additions and 32 deletions

View File

@ -5,6 +5,8 @@
- Don't hang indefinitely and provide nicer error messages when a connection - Don't hang indefinitely and provide nicer error messages when a connection
can't be established. can't be established.
- Remove `Login` and `Registration` tabs and consolidate into one panel. - Remove `Login` and `Registration` tabs and consolidate into one panel.
- #828 Add routing for the `#converse-login` and `#converse-register` URL
fragments, which will render the registration and login forms respectively.
## 3.2.1 (2017-08-29) ## 3.2.1 (2017-08-29)

View File

@ -528,7 +528,8 @@
Promise.all([ Promise.all([
_converse.api.waitUntil('chatBoxesFetched'), _converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered') _converse.api.waitUntil('roomsPanelRendered')
]).then(initBookmarks); ]).then(initBookmarks)
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
const afterReconnection = function () { const afterReconnection = function () {
if (!_converse.allow_bookmarks) { if (!_converse.allow_bookmarks) {

View File

@ -187,6 +187,8 @@
xhr_user_search_url: '' xhr_user_search_url: ''
}); });
_converse.api.promises.add('controlboxInitialized');
const LABEL_CONTACTS = __('Contacts'); const LABEL_CONTACTS = __('Contacts');
_converse.addControlBox = () => { _converse.addControlBox = () => {
@ -223,6 +225,7 @@
.then(this.insertRoster.bind(this)) .then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
_converse.emit('controlboxInitialized');
}, },
render () { render () {

View File

@ -1878,6 +1878,8 @@
_converse.logIn(); _converse.logIn();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
Backbone.history.start();
if (!_.isUndefined(_converse.connection) && if (!_.isUndefined(_converse.connection) &&
_converse.connection.service === 'jasmine tests') { _converse.connection.service === 'jasmine tests') {
return _converse; return _converse;

View File

@ -66,12 +66,36 @@
const _converse = this.__super__._converse; const _converse = this.__super__._converse;
this.__super__.initialize.apply(this, arguments); this.__super__.initialize.apply(this, arguments);
this.registerlink = new _converse.RegisterLink(); this.registerlink = new _converse.RegisterLink();
this.el.appendChild(this.registerlink.el); const div = document.createElement('div');
div.innerHTML = tpl_register_link({'__': _converse.__})
this.el.appendChild(div);
} }
}, },
ControlBoxView: { ControlBoxView: {
initialize () {
this.__super__.initialize.apply(this, arguments);
this.model.on('change:active-form', this.showLoginOrRegisterForm.bind(this))
},
showLoginOrRegisterForm (ev) {
const { _converse } = this.__super__;
if (this.model.get('active-form') == "register") {
this.loginpanel.el.classList.add('hidden');
this.registerpanel.el.classList.remove('hidden');
if (_converse.registration_domain &&
ev.target.getAttribute('data-id') === "register" &&
!this.model.get('registration_form_rendered')) {
this.registerpanel.fetchRegistrationForm(_converse.registration_domain);
}
} else {
this.loginpanel.el.classList.remove('hidden');
this.registerpanel.el.classList.add('hidden');
}
},
renderRegistrationPanel () { renderRegistrationPanel () {
const { _converse } = this.__super__; const { _converse } = this.__super__;
if (_converse.allow_registration) { if (_converse.allow_registration) {
@ -84,6 +108,7 @@
'afterend', 'afterend',
this.registerpanel.el this.registerpanel.el
); );
this.showLoginOrRegisterForm();
} }
return this; return this;
}, },
@ -118,33 +143,37 @@
providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page
}); });
_converse.RegistrationRouter = Backbone.Router.extend({
initialize () {
this.route('converse-login', _.partial(this.setActiveForm, 'login'));
this.route('converse-register', _.partial(this.setActiveForm, 'register'));
},
setActiveForm (value) {
_converse.api.waitUntil('controlboxInitialized').then(() => {
const controlbox = _converse.chatboxes.get('controlbox')
if (controlbox.get('connected')) {
controlbox.save({'active-form': value});
} else {
controlbox.set({'active-form': value});
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
});
const router = new _converse.RegistrationRouter();
_converse.RegisterLink = Backbone.View.extend({ _converse.RegisterLink = Backbone.View.extend({
tagName: 'div', tagName: 'div',
events: {
'click .register-account': 'showRegistrationForm'
},
initialize () { initialize () {
this.render(); this.render();
}, },
render () { render () {
this.el.innerHTML = tpl_register_link({'__': __});
return this; return this;
},
showRegistrationForm (ev) {
ev.preventDefault();
document.querySelector("#converse-register-panel").classList.remove('hidden');
document.querySelector("#converse-login-panel").classList.add('hidden');
if (!_.isUndefined(_converse.chatboxes.browserStorage)) {
this.model.save({'active-panel': "register"});
}
if (_converse.registration_domain &&
ev.target.getAttribute('data-id') === "register" &&
!this.model.get('registration_form_rendered')) {
this.registerpanel.fetchRegistrationForm(_converse.registration_domain);
}
} }
}); });
@ -153,8 +182,7 @@
id: "converse-register-panel", id: "converse-register-panel",
className: 'controlbox-pane', className: 'controlbox-pane',
events: { events: {
'submit form#converse-register': 'onProviderChosen', 'submit form#converse-register': 'onProviderChosen'
'click .login-here': 'showLoginForm'
}, },
initialize (cfg) { initialize (cfg) {
@ -193,15 +221,6 @@
}; };
}, },
showLoginForm (ev) {
ev.preventDefault();
document.querySelector("#converse-login-panel").classList.remove('hidden');
document.querySelector("#converse-register-panel").classList.add('hidden');
if (!_.isUndefined(_converse.chatboxes.browserStorage)) {
this.model.save({'active-panel': "login"});
}
},
getRegistrationFields (req, _callback, raw) { getRegistrationFields (req, _callback, raw) {
/* Send an IQ stanza to the XMPP server asking for the /* Send an IQ stanza to the XMPP server asking for the
* registration fields. * registration fields.

View File

@ -16,5 +16,5 @@
<p style="margin-top: 1em">{{{ __("Already have a Jabber/XMPP chat account?") }}}</p> <p style="margin-top: 1em">{{{ __("Already have a Jabber/XMPP chat account?") }}}</p>
<p style="margin-top: 0.5em"> <p style="margin-top: 0.5em">
<a class="login-here toggle-register-login" href="#login">{{{__("Log in here")}}}</a> <a class="login-here toggle-register-login" href="#converse-login">{{{__("Log in here")}}}</a>
</p> </p>