Commit a2be2567 authored by JC Brand's avatar JC Brand

Allow auto_login also with a provided jid and password.

* Update the docs to mention the new ``authentication`` option.
* Update failing tests due to ``prebind`` being replaced with ``authentication``.
* Rename 'manual' value for authentication to 'login' since it's used in both manual and auto cases.
parent a2d27ee9
......@@ -182,7 +182,7 @@
// Constants
// ---------
var MANUAL = "manual";
var LOGIN = "login";
var ANONYMOUS = "anonymous";
var PREBIND = "prebind";
......@@ -261,7 +261,8 @@
message_carbons: false,
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
play_sounds: false,
authentication: 'manual', // Available values are "manual", "prebind", "anonymous".
password: undefined,
authentication: 'login', // Available values are "login", "prebind", "anonymous".
prebind: false, // XXX: Deprecated, use "authentication" instead.
prebind_url: null,
providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page
......@@ -5160,7 +5161,7 @@
initialize: function (cfg) {
cfg.$parent.html(this.$el.html(
converse.templates.login_panel({
'MANUAL': MANUAL,
'LOGIN': LOGIN,
'ANONYMOUS': ANONYMOUS,
'PREBIND': PREBIND,
'auto_login': converse.auto_login,
......@@ -5378,8 +5379,19 @@
if (rid && sid && jid) {
this.session.save({rid: rid}); // The RID needs to be increased with each request.
this.connection.attach(jid, sid, rid, this.onConnect);
} else if (this.authentication === ANONYMOUS && this.auto_login) {
this.connection.connect(this.jid, null, this.onConnect);
} else if (this.auto_login) {
if (!this.jid) {
throw new Error("initConnection: If you use auto_login, you also need to provide a jid value");
}
if (this.authentication === ANONYMOUS) {
this.connection.connect(this.jid, null, this.onConnect);
} else if (this.authentication === LOGIN) {
if (!this.password) {
throw new Error("initConnection: If you use auto_login and "+
"authentication='login' then you also need to provide a password.");
}
this.connection.connect(this.jid, this.password, this.onConnect);
}
}
}
} else if (this.authentication == "prebind") {
......
This diff is collapsed.
......@@ -28,12 +28,8 @@ bottom of your page (after the closing *</body>* element).
require(['converse'], function (converse) {
converse.initialize({
auto_list_rooms: false,
auto_subscribe: false,
bosh_service_url: 'https://bind.conversejs.org', // Please use this connection manager only for testing purposes
hide_muc_server: false,
i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
prebind: false,
show_controlbox_by_default: true,
roster_groups: true
});
......
......@@ -20,37 +20,39 @@
describe("with prebind", function () {
it("needs a jid when also using keepalive", function () {
var authentication = converse.authentication;
var connection = converse.connection;
var jid = converse.jid;
converse.bosh_service_url = "localhost";
converse.connection = undefined;
converse.jid = undefined;
converse.keepalive = true;
converse.prebind = true;
converse.authentication = "prebind";
expect(converse.initConnection.bind(converse)).toThrow(
new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user."));
converse.authentication= authentication;
converse.bosh_service_url = undefined;
converse.connection = connection;
converse.jid = jid;
converse.keepalive = undefined;
converse.prebind = undefined;
});
it("needs jid, rid and sid values when not using keepalive", function () {
var authentication = converse.authentication;
var connection = converse.connection;
var jid = converse.jid;
converse.bosh_service_url = "localhost";
converse.connection = undefined;
converse.jid = undefined;
converse.keepalive = false;
converse.prebind = true;
converse.authentication = "prebind";
expect(converse.initConnection.bind(converse)).toThrow(
new Error("initConnection: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values"));
converse.authentication= authentication;
converse.bosh_service_url = undefined;
converse.connection = connection;
converse.jid = jid;
converse.keepalive = undefined;
converse.prebind = undefined;
});
});
});
......
......@@ -3,7 +3,7 @@
<span class="spinner login-submit"/>
{[ } ]}
{[ if (!auto_login) { ]}
{[ if (authentication == MANUAL) { ]}
{[ if (authentication == LOGIN) { ]}
<label>{{label_username}}</label>
<input type="email" name="jid" placeholder="user@server">
<label>{{label_password}}</label>
......
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