Commit 46ca6c7d authored by JC Brand's avatar JC Brand

Make the router global and clear login/register fragments

upon login or after registering.
parent 61ed55db
...@@ -550,6 +550,10 @@ ...@@ -550,6 +550,10 @@
jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+resource; 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.reset();
_converse.connection.connect(jid, password, _converse.onConnectStatusChanged); _converse.connection.connect(jid, password, _converse.onConnectStatusChanged);
} }
......
...@@ -230,6 +230,9 @@ ...@@ -230,6 +230,9 @@
} }
}; };
_converse.router = new Backbone.Router();
_converse.initialize = function (settings, callback) { _converse.initialize = function (settings, callback) {
"use strict"; "use strict";
settings = !_.isUndefined(settings) ? settings : {}; settings = !_.isUndefined(settings) ? settings : {};
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
// relevant objects or classes. // relevant objects or classes.
// //
// New functions which don't exist yet can also be added. // New functions which don't exist yet can also be added.
LoginPanel: { LoginPanel: {
render: function (cfg) { render: function (cfg) {
...@@ -145,19 +145,15 @@ ...@@ -145,19 +145,15 @@
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
}); });
const RegistrationRouter = Backbone.Router.extend({
initialize () { function setActiveForm (value) {
this.route('converse/login', _.partial(this.setActiveForm, 'login')); _converse.api.waitUntil('controlboxInitialized').then(() => {
this.route('converse/register', _.partial(this.setActiveForm, 'register')); const controlbox = _converse.chatboxes.get('controlbox')
}, controlbox.set({'active-form': value});
setActiveForm (value) { }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.api.waitUntil('controlboxInitialized').then(() => { }
const controlbox = _converse.chatboxes.get('controlbox') _converse.router.route('converse/login', _.partial(setActiveForm, 'login'));
controlbox.set({'active-form': value}); _converse.router.route('converse/register', _.partial(setActiveForm, 'register'));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
});
const router = new RegistrationRouter();
_converse.RegisterPanel = Backbone.View.extend({ _converse.RegisterPanel = Backbone.View.extend({
...@@ -419,11 +415,14 @@ ...@@ -419,11 +415,14 @@
); );
this.abortRegistration(); this.abortRegistration();
} else if (status_code === Strophe.Status.REGISTERED) { } else if (status_code === Strophe.Status.REGISTERED) {
router.navigate(); // Strip the URL fragment
_converse.log("Registered successfully."); _converse.log("Registered successfully.");
_converse.connection.reset(); _converse.connection.reset();
this.showSpinner(); this.showSpinner();
if (_.includes(["converse/login", "converse/register"], Backbone.History.getFragment())) {
_converse.router.navigate('', {'replace': true});
}
if (this.fields.password && this.fields.username) { if (this.fields.password && this.fields.username) {
// automatically log the user in // automatically log the user in
_converse.connection.connect( _converse.connection.connect(
...@@ -458,7 +457,7 @@ ...@@ -458,7 +457,7 @@
form.insertAdjacentHTML( form.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_form_input({ tpl_form_input({
'label': key, 'label': key,
'name': key, 'name': key,
'placeholder': key, 'placeholder': key,
'required': true, 'required': true,
......
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