diff --git a/docs/source/development.rst b/docs/source/development.rst index ea446e38c..fa18dbe1d 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -400,6 +400,22 @@ The "user" grouping This grouping collects API functions related to the current logged in user. +login +~~~~~ + +Logs the user in. This method can accept a map with the credentials, like this: + +.. code-block:: javascript + + converse.user.login({ + 'jid': 'dummy@example.com', + 'password': 'secret' + }); + +or it can be called without any parameters, in which case converse.js will try +to log the user in by calling the `prebind_url` or `credentials_url` depending +on whether prebinding is used or not. + logout ~~~~~~ diff --git a/src/converse-api.js b/src/converse-api.js index e8ae4bb1c..e8027d5e4 100644 --- a/src/converse-api.js +++ b/src/converse-api.js @@ -34,6 +34,9 @@ }, }, 'user': { + 'login': function (credentials) { + converse.logIn(credentials); + }, 'logout': function () { converse.logOut(); }, diff --git a/src/converse-core.js b/src/converse-core.js index 59251ea06..2d49305eb 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -443,7 +443,7 @@ if (converse.disconnection_cause === Strophe.Status.CONNFAIL || (converse.disconnection_cause === Strophe.Status.AUTHFAIL && converse.credentials_url && - converse.auto_login + !converse.logged_out ) ) { converse.reconnect(condition); @@ -1703,6 +1703,20 @@ } }; + this.logIn = function (credentials) { + if (credentials) { + this.autoLogin(credentials); + } else { + // We now try to resume or automatically set up a new session. + // Otherwise the user will be shown a login form. + if (this.authentication === converse.PREBIND) { + this.attemptPreboundSession(); + } else { + this.attemptNonPreboundSession(); + } + } + }; + this.initConnection = function () { if (this.connection && this.connection.connected) { this.setUpXMLLogging(); @@ -1719,13 +1733,7 @@ throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified."); } this.setUpXMLLogging(); - // We now try to resume or automatically set up a new session. - // Otherwise the user will be shown a login form. - if (this.authentication === converse.PREBIND) { - this.attemptPreboundSession(); - } else { - this.attemptNonPreboundSession(); - } + this.logIn(); } };