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