Commit 6ef2e503 authored by JC Brand's avatar JC Brand

Merge branch 'anon_login'

parents 960cf4a5 18fd854d
...@@ -15,6 +15,7 @@ analytics.js ...@@ -15,6 +15,7 @@ analytics.js
.sass-cache .sass-cache
ruby ruby
bourbon bourbon
Gemfile.lock
Backbone.Overview Backbone.Overview
tags tags
......
...@@ -182,6 +182,10 @@ ...@@ -182,6 +182,10 @@
// Constants // Constants
// --------- // ---------
var LOGIN = "login";
var ANONYMOUS = "anonymous";
var PREBIND = "prebind";
var UNENCRYPTED = 0; var UNENCRYPTED = 0;
var UNVERIFIED= 1; var UNVERIFIED= 1;
var VERIFIED= 2; var VERIFIED= 2;
...@@ -240,6 +244,7 @@ ...@@ -240,6 +244,7 @@
allow_registration: true, allow_registration: true,
animate: true, animate: true,
auto_list_rooms: false, auto_list_rooms: false,
auto_login: false, // Currently only used in connection with anonymous login
auto_reconnect: false, auto_reconnect: false,
auto_subscribe: false, auto_subscribe: false,
bosh_service_url: undefined, // The BOSH connection manager URL. bosh_service_url: undefined, // The BOSH connection manager URL.
...@@ -256,7 +261,9 @@ ...@@ -256,7 +261,9 @@
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,
prebind: false, password: undefined,
authentication: 'login', // Available values are "login", "prebind", "anonymous".
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
rid: undefined, rid: undefined,
...@@ -284,6 +291,16 @@ ...@@ -284,6 +291,16 @@
// Allow only whitelisted configuration attributes to be overwritten // Allow only whitelisted configuration attributes to be overwritten
_.extend(this, _.pick(settings, Object.keys(this.default_settings))); _.extend(this, _.pick(settings, Object.keys(this.default_settings)));
// BBB
if (this.prebind === true) { this.authentication = PREBIND; }
if (this.authentication === ANONYMOUS) {
if (!this.jid) {
throw("Config Error: you need to provide the server's domain via the " +
"'jid' option when using anonymous authentication.");
}
}
if (settings.visible_toolbar_buttons) { if (settings.visible_toolbar_buttons) {
_.extend( _.extend(
this.visible_toolbar_buttons, this.visible_toolbar_buttons,
...@@ -431,7 +448,7 @@ ...@@ -431,7 +448,7 @@
this.reconnect = function () { this.reconnect = function () {
converse.giveFeedback(__('Reconnecting'), 'error'); converse.giveFeedback(__('Reconnecting'), 'error');
if (!converse.prebind) { if (converse.authentication !== "prebind") {
this.connection.connect( this.connection.connect(
this.connection.jid, this.connection.jid,
this.connection.pass, this.connection.pass,
...@@ -690,7 +707,7 @@ ...@@ -690,7 +707,7 @@
this.OTR = Backbone.Model.extend({ this.OTR = Backbone.Model.extend({
// A model for managing OTR settings. // A model for managing OTR settings.
getSessionPassphrase: function () { getSessionPassphrase: function () {
if (converse.prebind) { if (converse.authentication === 'prebind') {
var key = b64_sha1(converse.connection.jid), var key = b64_sha1(converse.connection.jid),
pass = window.sessionStorage[key]; pass = window.sessionStorage[key];
if (typeof pass === 'undefined') { if (typeof pass === 'undefined') {
...@@ -1730,8 +1747,7 @@ ...@@ -1730,8 +1747,7 @@
}, },
addContact: function (jid, name) { addContact: function (jid, name) {
name = _.isEmpty(name)? jid: name; converse.connection.roster.add(jid, _.isEmpty(name)? jid: name, [], function (iq) {
converse.connection.roster.add(jid, name, [], function (iq) {
converse.connection.roster.subscribe(jid, null, converse.xmppstatus.get('fullname')); converse.connection.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
}); });
} }
...@@ -3139,13 +3155,6 @@ ...@@ -3139,13 +3155,6 @@
}); });
} }
if (msgid && chatbox.messages.findWhere({msgid: msgid})) { if (msgid && chatbox.messages.findWhere({msgid: msgid})) {
// FIXME: There's still a bug here..
// If a duplicate message is received just after the chat
// box was closed, then it'll open again (due to it being
// created here above), with no new messages.
// The solution is mostly likely to not let chat boxes show
// automatically when they are created, but to require
// "show" to be called explicitly.
return true; // We already have this message stored. return true; // We already have this message stored.
} }
if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) { if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
...@@ -5154,8 +5163,14 @@ ...@@ -5154,8 +5163,14 @@
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({
'LOGIN': LOGIN,
'ANONYMOUS': ANONYMOUS,
'PREBIND': PREBIND,
'auto_login': converse.auto_login,
'authentication': converse.authentication,
'label_username': __('XMPP Username:'), 'label_username': __('XMPP Username:'),
'label_password': __('Password:'), 'label_password': __('Password:'),
'label_anon_login': __('Click here to log in anonymously'),
'label_login': __('Log In') 'label_login': __('Log In')
}) })
)); ));
...@@ -5173,8 +5188,12 @@ ...@@ -5173,8 +5188,12 @@
authenticate: function (ev) { authenticate: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
var $form = $(ev.target), var $form = $(ev.target);
$jid_input = $form.find('input[name=jid]'), if (converse.authentication === ANONYMOUS) {
this.connect($form, converse.jid, null);
return;
}
var $jid_input = $form.find('input[name=jid]'),
jid = $jid_input.val(), jid = $jid_input.val(),
$pw_input = $form.find('input[name=password]'), $pw_input = $form.find('input[name=password]'),
password = $pw_input.val(), password = $pw_input.val(),
...@@ -5203,12 +5222,15 @@ ...@@ -5203,12 +5222,15 @@
}, },
connect: function ($form, jid, password) { connect: function ($form, jid, password) {
var resource;
if ($form) { if ($form) {
$form.find('input[type=submit]').hide().after('<span class="spinner login-submit"/>'); $form.find('input[type=submit]').hide().after('<span class="spinner login-submit"/>');
} }
var resource = Strophe.getResourceFromJid(jid); if (jid) {
if (!resource) { resource = Strophe.getResourceFromJid(jid);
jid += '/converse.js-' + Math.floor(Math.random()*139749825).toString(); if (!resource) {
jid += '/converse.js-' + Math.floor(Math.random()*139749825).toString();
}
} }
converse.connection.connect(jid, password, converse.onConnect); converse.connection.connect(jid, password, converse.onConnect);
}, },
...@@ -5341,7 +5363,7 @@ ...@@ -5341,7 +5363,7 @@
rid = this.session.get('rid'); rid = this.session.get('rid');
sid = this.session.get('sid'); sid = this.session.get('sid');
jid = this.session.get('jid'); jid = this.session.get('jid');
if (this.prebind) { if (this.authentication === "prebind") {
if (!this.jid) { if (!this.jid) {
throw new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user."); throw new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user.");
} }
...@@ -5359,11 +5381,23 @@ ...@@ -5359,11 +5381,23 @@
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.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") {
// Prebind without keepalive // prebind is used without keepalive
} else if (this.prebind) {
if (this.jid && this.sid && this.rid) { if (this.jid && this.sid && this.rid) {
this.connection.attach(this.jid, this.sid, this.rid, this.onConnect); this.connection.attach(this.jid, this.sid, this.rid, this.onConnect);
} else { } else {
...@@ -5517,7 +5551,6 @@ ...@@ -5517,7 +5551,6 @@
converse.connection.roster.add(jid, _.isEmpty(name)? jid: name, [], function (iq) { converse.connection.roster.add(jid, _.isEmpty(name)? jid: name, [], function (iq) {
converse.connection.roster.subscribe(jid, null, converse.xmppstatus.get('fullname')); converse.connection.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
}); });
return true;
} }
}, },
'chats': { 'chats': {
......
...@@ -353,7 +353,8 @@ ...@@ -353,7 +353,8 @@
#conversejs .hor_centered { #conversejs .hor_centered {
text-align: center; text-align: center;
display: block; display: block;
margin: 0 auto; } margin: 0 auto;
clear: both; }
#conversejs .toggle-controlbox, #conversejs .toggle-controlbox,
#conversejs #minimized-chats { #conversejs #minimized-chats {
border-top-left-radius: 4px; border-top-left-radius: 4px;
...@@ -788,27 +789,32 @@ ...@@ -788,27 +789,32 @@
text-overflow: ellipsis; text-overflow: ellipsis;
overflow-x: hidden; } overflow-x: hidden; }
#conversejs dd.available-chatroom { #conversejs dd.available-chatroom {
display: inline-block; border: none;
overflow-x: hidden; clear: both;
text-overflow: ellipsis; color: #6C4C44;
display: block;
font-weight: bold;
overflow: hidden;
padding: 0.25em 0.5em; padding: 0.25em 0.5em;
text-overflow: ellipsis;
text-shadow: 0 1px 0 #FAFAFA;
white-space: nowrap; } white-space: nowrap; }
#conversejs dd.available-chatroom a.open-room { #conversejs dd.available-chatroom a.open-room {
width: 150px; } width: 150px; }
#conversejs dd.available-chatroom:hover a.room-info { #conversejs dd.available-chatroom:hover {
display: inline-block; background-color: #E3C9C1; }
font-size: 14px; } #conversejs dd.available-chatroom:hover .room-info {
#conversejs dd.available-chatroom, display: inline-block;
font-size: 14px; }
#conversejs #converse-roster dd { #conversejs #converse-roster dd {
font-weight: bold;
border: none; border: none;
display: block;
color: #6C4C44;
text-shadow: 0 1px 0 #FAFAFA;
clear: both; clear: both;
overflow-y: hidden; } color: #6C4C44;
display: block;
font-weight: bold;
overflow-y: hidden;
text-shadow: 0 1px 0 #FAFAFA; }
#conversejs .roster-group:hover, #conversejs .roster-group:hover,
#conversejs dd.available-chatroom:hover,
#conversejs #converse-roster dd:hover { #conversejs #converse-roster dd:hover {
background-color: #E3C9C1; } background-color: #E3C9C1; }
#conversejs .chatbox, #conversejs .chatbox,
...@@ -981,15 +987,15 @@ ...@@ -981,15 +987,15 @@
font-weight: bold; font-weight: bold;
height: auto; height: auto;
margin: 4px; } margin: 4px; }
#conversejs #converse-register .login-submit, #conversejs #converse-register .login-submit, #conversejs #converse-register .submit, #conversejs #converse-login .login-submit, #conversejs #converse-login .submit {
#conversejs #converse-login .login-submit,
#conversejs #converse-register .submit,
#conversejs #converse-login .submit {
height: 30px; height: 30px;
padding: 0px; padding: 0px;
font-size: 14px; } font-size: 14px; }
#conversejs #converse-login .submit { #conversejs #converse-register .submit, #conversejs #converse-login .submit {
margin: 1em 0; } margin: 1em 0; }
#conversejs #converse-register .login-anon, #conversejs #converse-login .login-anon {
height: auto;
white-space: normal; }
#conversejs form.add-chatroom { #conversejs form.add-chatroom {
background: none; background: none;
padding: 0.5em; } padding: 0.5em; }
......
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
<script> <script>
require(['converse'], function (converse) { require(['converse'], function (converse) {
converse.initialize({ converse.initialize({
auto_login: true,
allow_registration: false,
allow_logout: false,
authentication: "anonymous",
jid: "opkode.im",
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
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
keepalive: true, keepalive: true,
......
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
}); });
......
...@@ -289,6 +289,7 @@ ...@@ -289,6 +289,7 @@
text-align: center; text-align: center;
display: block; display: block;
margin: 0 auto; margin: 0 auto;
clear: both;
} }
.toggle-controlbox, .toggle-controlbox,
...@@ -897,34 +898,39 @@ ...@@ -897,34 +898,39 @@
} }
dd.available-chatroom { dd.available-chatroom {
display: inline-block; border: none;
overflow-x: hidden; clear: both;
text-overflow: ellipsis; color: $text-color;
display: block;
font-weight: bold;
overflow: hidden;
padding: 0.25em 0.5em; padding: 0.25em 0.5em;
text-overflow: ellipsis;
text-shadow: 0 1px 0 $text-shadow-color;
white-space: nowrap; white-space: nowrap;
a.open-room { a.open-room {
width: 150px; width: 150px;
} }
&:hover {
background-color: $highlight-color;
.room-info {
display: inline-block;
font-size: 14px;
}
}
} }
dd.available-chatroom:hover a.room-info {
display: inline-block;
font-size: 14px;
}
dd.available-chatroom,
#converse-roster dd { #converse-roster dd {
font-weight: bold;
border: none; border: none;
display: block;
color: $text-color;
text-shadow: 0 1px 0 $text-shadow-color;
clear: both; clear: both;
color: $text-color;
display: block;
font-weight: bold;
overflow-y: hidden; overflow-y: hidden;
text-shadow: 0 1px 0 $text-shadow-color;
} }
.roster-group:hover, .roster-group:hover,
dd.available-chatroom:hover,
#converse-roster dd:hover { #converse-roster dd:hover {
background-color: $highlight-color; background-color: $highlight-color;
} }
...@@ -1162,19 +1168,21 @@ ...@@ -1162,19 +1168,21 @@
margin: 4px; margin: 4px;
} }
#converse-register .login-submit, #converse-register, #converse-login {
#converse-login .login-submit, .login-submit, .submit {
#converse-register .submit, height: 30px;
#converse-login .submit { padding: 0px;
height: 30px; font-size: $font-size;
padding: 0px; }
font-size: $font-size; .submit {
} margin: 1em 0;
}
#converse-login .submit { .login-anon {
margin: 1em 0; height: auto;
white-space: normal;
}
} }
form.add-chatroom { form.add-chatroom {
background: none; background: none;
padding: 0.5em; padding: 0.5em;
......
...@@ -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;
}); });
}); });
}); });
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
var pp; var pp;
// With no prebind, the user's XMPP password is used and nothing is // With no prebind, the user's XMPP password is used and nothing is
// stored in session storage. // stored in session storage.
this.prebind = false; this.authentication = "manual";
this.connection.pass = 's3cr3t!'; this.connection.pass = 's3cr3t!';
expect(this.otr.getSessionPassphrase()).toBe(this.connection.pass); expect(this.otr.getSessionPassphrase()).toBe(this.connection.pass);
expect(window.sessionStorage.length).toBe(0); expect(window.sessionStorage.length).toBe(0);
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// With prebind, a random passphrase is generated and stored in // With prebind, a random passphrase is generated and stored in
// session storage. // session storage.
this.prebind = true; this.authentication = "prebind";
pp = this.otr.getSessionPassphrase(); pp = this.otr.getSessionPassphrase();
expect(pp).not.toBe(this.connection.pass); expect(pp).not.toBe(this.connection.pass);
expect(window.sessionStorage.length).toBe(1); expect(window.sessionStorage.length).toBe(1);
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
expect(pp).toBe(window.sessionStorage[b64_sha1(converse.connection.jid)]); expect(pp).toBe(window.sessionStorage[b64_sha1(converse.connection.jid)]);
// Clean up // Clean up
this.prebind = false; this.authentication = "manual";
}, converse)); }, converse));
}, converse, mock, test_utils)); }, converse, mock, test_utils));
})); }));
<form id="converse-login" method="post"> <form id="converse-login" method="post">
<label>{{label_username}}</label> {[ if (auto_login) { ]}
<input type="email" name="jid" placeholder="user@server"> <span class="spinner login-submit"/>
<label>{{label_password}}</label> {[ } ]}
<input type="password" name="password" placeholder="password"> {[ if (!auto_login) { ]}
<input class="submit" type="submit" value="{{label_login}}"> {[ if (authentication == LOGIN) { ]}
<span class="conn-feedback"></span> <label>{{label_username}}</label>
<input type="email" name="jid" placeholder="user@server">
<label>{{label_password}}</label>
<input type="password" name="password" placeholder="password">
<input class="submit" type="submit" value="{{label_login}}">
<span class="conn-feedback"></span>
{[ } ]}
{[ if (authentication == ANONYMOUS) { ]}
<input type="submit" class="submit login-anon" value="{{label_anon_login}}"/>
{[ } ]}
{[ if (authentication == PREBIND) { ]}
<p>Disconnected.</p>
{[ } ]}
{[ } ]}
</form> </form>
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