Add login API method.

This commit is contained in:
JC Brand 2016-04-13 11:52:28 +00:00
parent 0564f0f592
commit e09328df6a
3 changed files with 35 additions and 8 deletions

View File

@ -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
~~~~~~

View File

@ -34,6 +34,9 @@
},
},
'user': {
'login': function (credentials) {
converse.logIn(credentials);
},
'logout': function () {
converse.logOut();
},

View File

@ -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();
}
};