Commit 9bf00241 authored by JC Brand's avatar JC Brand

Updates #721 Restore sessions when logging in anonymously

together with keepalive.
parent 9a09409e
# Changelog
## 2.0.2 (Unreleased)
- #721 keepalive not working with anonymous authentication [jcbrand]
## 2.0.1 (2016-11-07)
- #203 New configuration setting [muc_domain](https://conversejs.org/docs/html/configuration.html#muc_domain) [jcbrand]
- #705 White content after submitting password on chatrooms [jcbrand]
......
......@@ -46,13 +46,11 @@
}));
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (converse) {
var authentication = converse.authentication;
var jid = converse.jid;
delete converse.jid;
converse.authentication = "prebind";
expect(converse.logIn.bind(converse)).toThrow(
new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values"));
converse.authentication= authentication;
new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values or a prebind_url."));
converse.bosh_service_url = undefined;
converse.jid = jid;
}));
......
......@@ -1757,31 +1757,30 @@
};
this.startNewBOSHSession = function () {
var that = this;
$.ajax({
url: this.prebind_url,
type: 'GET',
dataType: "json",
success: function (response) {
this.connection.attach(
that.connection.attach(
response.jid,
response.sid,
response.rid,
this.onConnectStatusChanged
that.onConnectStatusChanged
);
}.bind(this),
},
error: function (response) {
delete this.connection;
this.emit('noResumeableSession');
}.bind(this)
delete that.connection;
that.emit('noResumeableSession');
}
});
};
this.attemptPreboundSession = function (tokens) {
/* Handle session resumption or initialization when prebind is being used.
*/
if (this.jid && this.sid && this.rid) {
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
} else if (this.keepalive) {
if (this.keepalive) {
if (!this.jid) {
throw new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, "+
"you must supply the JID of the current user.");
......@@ -1792,18 +1791,16 @@
this.log("Could not restore session for jid: "+this.jid+" Error message: "+e.message);
this.clearSession(); // If there's a roster, we want to clear it (see #555)
}
} else {
throw new Error("attemptPreboundSession: If you use prebind and not keepalive, "+
"then you MUST supply JID, RID and SID values");
}
// We haven't been able to attach yet. Let's see if there
// is a prebind_url, otherwise there's nothing with which
// we can attach.
if (this.prebind_url) {
this.startNewBOSHSession();
// No keepalive, or session resumption has failed.
if (this.jid && this.sid && this.rid) {
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
} else if (this.prebind_url) {
return this.startNewBOSHSession();
} else {
delete this.connection;
this.emit('noResumeableSession');
throw new Error("attemptPreboundSession: If you use prebind and not keepalive, "+
"then you MUST supply JID, RID and SID values or a prebind_url.");
}
};
......@@ -1844,7 +1841,7 @@
}
};
this.attemptNonPreboundSession = function () {
this.attemptNonPreboundSession = function (credentials) {
/* Handle session resumption or initialization when prebind is not being used.
*
* Two potential options exist and are handled in this method:
......@@ -1860,7 +1857,11 @@
}
}
if (this.auto_login) {
if (this.credentials_url) {
if (credentials) {
// When credentials are passed in, they override prebinding
// or credentials fetching via HTTP
this.autoLogin(credentials);
} else if (this.credentials_url) {
this.fetchLoginCredentials().done(this.autoLogin.bind(this));
} else if (!this.jid) {
throw new Error(
......@@ -1870,24 +1871,19 @@
"username and password can be fetched (via credentials_url)."
);
} else {
// Probably ANONYMOUS login
this.autoLogin();
}
}
};
this.logIn = function (credentials) {
if (credentials || this.authentication === converse.ANONYMOUS) {
// When credentials are passed in, they override prebinding
// or credentials fetching via HTTP
this.autoLogin(credentials);
// 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 {
// 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.attemptNonPreboundSession(credentials);
}
};
......
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