Make the router global and clear login/register fragments

upon login or after registering.
This commit is contained in:
JC Brand 2017-10-31 21:47:27 +01:00
parent 61ed55dbaa
commit 46ca6c7de2
3 changed files with 22 additions and 16 deletions

View File

@ -550,6 +550,10 @@
jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+resource;
}
}
if (_.includes(["converse/login", "converse/register"],
Backbone.history.getFragment())) {
_converse.router.navigate('', {'replace': true});
}
_converse.connection.reset();
_converse.connection.connect(jid, password, _converse.onConnectStatusChanged);
}

View File

@ -230,6 +230,9 @@
}
};
_converse.router = new Backbone.Router();
_converse.initialize = function (settings, callback) {
"use strict";
settings = !_.isUndefined(settings) ? settings : {};

View File

@ -145,19 +145,15 @@
providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page
});
const 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')
controlbox.set({'active-form': value});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
});
const router = new RegistrationRouter();
function setActiveForm (value) {
_converse.api.waitUntil('controlboxInitialized').then(() => {
const controlbox = _converse.chatboxes.get('controlbox')
controlbox.set({'active-form': value});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
_converse.router.route('converse/login', _.partial(setActiveForm, 'login'));
_converse.router.route('converse/register', _.partial(setActiveForm, 'register'));
_converse.RegisterPanel = Backbone.View.extend({
@ -419,11 +415,14 @@
);
this.abortRegistration();
} else if (status_code === Strophe.Status.REGISTERED) {
router.navigate(); // Strip the URL fragment
_converse.log("Registered successfully.");
_converse.connection.reset();
this.showSpinner();
if (_.includes(["converse/login", "converse/register"], Backbone.History.getFragment())) {
_converse.router.navigate('', {'replace': true});
}
if (this.fields.password && this.fields.username) {
// automatically log the user in
_converse.connection.connect(