Commit 643c40f2 authored by JC Brand's avatar JC Brand

Respect `auto_login` after `finishInitialization`.

If `auto_login` is false, we shouldn't log in, so we only try to log in when
it is true. Otherwise we still try to restore the BOSH session (if applicable).
parent 18a2c885
...@@ -433,15 +433,14 @@ async function attemptNonPreboundSession (credentials) { ...@@ -433,15 +433,14 @@ async function attemptNonPreboundSession (credentials) {
} else { } else {
throw new Error("attemptNonPreboundSession: Could not find any credentials to log you in with!"); throw new Error("attemptNonPreboundSession: Could not find any credentials to log you in with!");
} }
} else { } else if ([_converse.ANONYMOUS, _converse.EXTERNAL].includes(_converse.authentication)) {
connect(); // Could be ANONYMOUS or EXTERNAL connect();
} }
} }
function connect (credentials) { function connect (credentials) {
if (_converse.authentication === _converse.ANONYMOUS || if ([_converse.ANONYMOUS, _converse.EXTERNAL].includes(_converse.authentication)) {
_converse.authentication === _converse.EXTERNAL) {
if (!_converse.jid) { if (!_converse.jid) {
throw new Error("Config Error: when using anonymous login " + throw new Error("Config Error: when using anonymous login " +
"you need to provide the server's domain via the 'jid' option. " + "you need to provide the server's domain via the 'jid' option. " +
...@@ -647,7 +646,11 @@ function finishInitialization () { ...@@ -647,7 +646,11 @@ function finishInitialization () {
initClientConfig(); initClientConfig();
initPlugins(); initPlugins();
_converse.initConnection(); _converse.initConnection();
if (_converse.auto_login) {
_converse.api.user.login(); _converse.api.user.login();
} else if (_converse.api.connection.isType('bosh')) {
_converse.restoreBOSHSession();
}
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
if (!Backbone.history.started) { if (!Backbone.history.started) {
Backbone.history.start(); Backbone.history.start();
...@@ -1450,8 +1453,6 @@ _converse.api = { ...@@ -1450,8 +1453,6 @@ _converse.api = {
* to log the user in by calling the `prebind_url` or `credentials_url` depending * to log the user in by calling the `prebind_url` or `credentials_url` depending
* on whether prebinding is used or not. * on whether prebinding is used or not.
* *
* Otherwise the user will be shown a login form.
*
* @method _converse.api.user.login * @method _converse.api.user.login
* @param {string} [jid] * @param {string} [jid]
* @param {string} [password] * @param {string} [password]
...@@ -1459,14 +1460,16 @@ _converse.api = { ...@@ -1459,14 +1460,16 @@ _converse.api = {
*/ */
async login (jid, password, reconnecting) { async login (jid, password, reconnecting) {
if (_converse.api.connection.isType('bosh')) { if (_converse.api.connection.isType('bosh')) {
if (reconnecting && const uses_prebind = (_converse.authentication === _converse.PREBIND && _converse.prebind_url);
_converse.authentication === _converse.PREBIND && if (!reconnecting && await _converse.restoreBOSHSession()) {
_converse.prebind_url) {
return _converse.startNewBOSHSession();
} else if (await _converse.restoreBOSHSession()) {
return; return;
} else if (reconnecting && uses_prebind) {
return _converse.startNewBOSHSession();
} }
} else if (_converse.authentication === _converse.PREBIND) {
throw new Error("authentication is set to 'prebind' but we don't have a BOSH connection");
} }
if (jid || _converse.jid) { if (jid || _converse.jid) {
// Reassign because we might have gained a resource // Reassign because we might have gained a resource
jid = await setUserJID(jid || _converse.jid); jid = await setUserJID(jid || _converse.jid);
...@@ -1478,7 +1481,6 @@ _converse.api = { ...@@ -1478,7 +1481,6 @@ _converse.api = {
/** /**
* Logs the user out of the current XMPP session. * Logs the user out of the current XMPP session.
*
* @method _converse.api.user.logout * @method _converse.api.user.logout
* @example _converse.api.user.logout(); * @example _converse.api.user.logout();
*/ */
......
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