Commit e09328df authored by JC Brand's avatar JC Brand

Add `login` API method.

parent 0564f0f5
...@@ -400,6 +400,22 @@ The "user" grouping ...@@ -400,6 +400,22 @@ The "user" grouping
This grouping collects API functions related to the current logged in user. 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 logout
~~~~~~ ~~~~~~
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
}, },
}, },
'user': { 'user': {
'login': function (credentials) {
converse.logIn(credentials);
},
'logout': function () { 'logout': function () {
converse.logOut(); converse.logOut();
}, },
......
...@@ -443,7 +443,7 @@ ...@@ -443,7 +443,7 @@
if (converse.disconnection_cause === Strophe.Status.CONNFAIL || if (converse.disconnection_cause === Strophe.Status.CONNFAIL ||
(converse.disconnection_cause === Strophe.Status.AUTHFAIL && (converse.disconnection_cause === Strophe.Status.AUTHFAIL &&
converse.credentials_url && converse.credentials_url &&
converse.auto_login !converse.logged_out
) )
) { ) {
converse.reconnect(condition); converse.reconnect(condition);
...@@ -1703,6 +1703,20 @@ ...@@ -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 () { this.initConnection = function () {
if (this.connection && this.connection.connected) { if (this.connection && this.connection.connected) {
this.setUpXMLLogging(); this.setUpXMLLogging();
...@@ -1719,13 +1733,7 @@ ...@@ -1719,13 +1733,7 @@
throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified."); throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified.");
} }
this.setUpXMLLogging(); this.setUpXMLLogging();
// We now try to resume or automatically set up a new session. this.logIn();
// Otherwise the user will be shown a login form.
if (this.authentication === converse.PREBIND) {
this.attemptPreboundSession();
} else {
this.attemptNonPreboundSession();
}
} }
}; };
......
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