More work on in band registration. updates #117
User gets automatically logged in if possible. Otherwise load login panel.
This commit is contained in:
parent
f4096ea9fb
commit
185f2c2491
132
converse.js
132
converse.js
@ -1897,6 +1897,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
giveFeedback: function (message, klass) {
|
||||||
|
// TODO:
|
||||||
|
alert(message);
|
||||||
|
},
|
||||||
|
|
||||||
onConnected: function () {
|
onConnected: function () {
|
||||||
if (this.model.get('connected')) {
|
if (this.model.get('connected')) {
|
||||||
this.render().initRoster();
|
this.render().initRoster();
|
||||||
@ -1951,13 +1956,21 @@
|
|||||||
var cfg = {'$parent': this.$el.find('.controlbox-panes'), 'model': this};
|
var cfg = {'$parent': this.$el.find('.controlbox-panes'), 'model': this};
|
||||||
if (!this.loginpanel) {
|
if (!this.loginpanel) {
|
||||||
this.loginpanel = new converse.LoginPanel(cfg);
|
this.loginpanel = new converse.LoginPanel(cfg);
|
||||||
this.registerpanel = new converse.RegisterPanel(cfg);
|
if (converse.allow_registration) {
|
||||||
|
this.registerpanel = new converse.RegisterPanel(cfg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.loginpanel.delegateEvents().initialize(cfg);
|
this.loginpanel.delegateEvents().initialize(cfg);
|
||||||
|
if (converse.allow_registration) {
|
||||||
|
this.registerpanel.delegateEvents().initialize(cfg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.loginpanel.render();
|
this.loginpanel.render();
|
||||||
this.registerpanel.render().$el.hide();
|
if (converse.allow_registration) {
|
||||||
|
this.registerpanel.render().$el.hide();
|
||||||
|
}
|
||||||
this.initDragResize();
|
this.initDragResize();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
renderContactsPanel: function () {
|
renderContactsPanel: function () {
|
||||||
@ -2040,7 +2053,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
switchTab: function (ev) {
|
switchTab: function (ev) {
|
||||||
ev.preventDefault();
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
var $tab = $(ev.target),
|
var $tab = $(ev.target),
|
||||||
$sibling = $tab.parent().siblings('li').children('a'),
|
$sibling = $tab.parent().siblings('li').children('a'),
|
||||||
$tab_panel = $($tab.attr('href'));
|
$tab_panel = $($tab.attr('href'));
|
||||||
@ -2048,6 +2061,7 @@
|
|||||||
$sibling.removeClass('current');
|
$sibling.removeClass('current');
|
||||||
$tab.addClass('current');
|
$tab.addClass('current');
|
||||||
$tab_panel.show();
|
$tab_panel.show();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
showHelpMessages: function (msgs) {
|
showHelpMessages: function (msgs) {
|
||||||
@ -4447,6 +4461,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
initialize: function (cfg) {
|
initialize: function (cfg) {
|
||||||
|
this.fields = {};
|
||||||
this.$parent = cfg.$parent;
|
this.$parent = cfg.$parent;
|
||||||
this.$tabs = cfg.$parent.parent().find('#controlbox-tabs');
|
this.$tabs = cfg.$parent.parent().find('#controlbox-tabs');
|
||||||
},
|
},
|
||||||
@ -4471,29 +4486,24 @@
|
|||||||
errors = false;
|
errors = false;
|
||||||
if (!domain) { errors = true; $domain_input.addClass('error'); }
|
if (!domain) { errors = true; $domain_input.addClass('error'); }
|
||||||
if (errors) { return; } // TODO provide error messages
|
if (errors) { return; } // TODO provide error messages
|
||||||
this.connect($form, domain);
|
$form.find('input[type=submit]').hide().after('<span class="spinner login-submit"/>');
|
||||||
|
converse.connection.register.connect(domain, $.proxy(this.onRegistering, this));
|
||||||
|
this.domain = domain;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
connect: function ($form, domain) {
|
|
||||||
if ($form) {
|
|
||||||
$form.find('input[type=submit]').hide().after('<span class="spinner login-submit"/>');
|
|
||||||
}
|
|
||||||
converse.connection.register.connect(domain, $.proxy(this.onRegistering, this));
|
|
||||||
},
|
|
||||||
|
|
||||||
giveFeedback: function (message, klass) {
|
giveFeedback: function (message, klass) {
|
||||||
$('.conn-feedback').attr('class', 'conn-feedback').text(message);
|
// TODO: need to add feedback element...
|
||||||
|
this.$('.conn-feedback').attr('class', 'conn-feedback').text(message);
|
||||||
if (klass) {
|
if (klass) {
|
||||||
$('.conn-feedback').addClass(klass);
|
$('.conn-feedback').addClass(klass);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRegistering: function (status, error) {
|
onRegistering: function (status, error) {
|
||||||
|
var that;
|
||||||
console.log('onRegistering');
|
console.log('onRegistering');
|
||||||
if (status === Strophe.Status.CONNECTING) {
|
if (status === Strophe.Status.CONNFAIL) {
|
||||||
converse.giveFeedback(__('Connecting'));
|
|
||||||
} else if (status === Strophe.Status.CONNFAIL) {
|
|
||||||
converse.renderLoginPanel();
|
converse.renderLoginPanel();
|
||||||
this.giveFeedback(__('Connection Failed'), 'error');
|
this.giveFeedback(__('Connection Failed'), 'error');
|
||||||
} else if (status === Strophe.Status.DISCONNECTING) {
|
} else if (status === Strophe.Status.DISCONNECTING) {
|
||||||
@ -4513,6 +4523,29 @@
|
|||||||
} else if (status == Strophe.Status.NOTACCEPTABLE) {
|
} else if (status == Strophe.Status.NOTACCEPTABLE) {
|
||||||
// TODO
|
// TODO
|
||||||
converse.log('NOTACCEPTABLE');
|
converse.log('NOTACCEPTABLE');
|
||||||
|
} else if (status == Strophe.Status.REGISTERED) {
|
||||||
|
converse.log("Registered successfully.");
|
||||||
|
that = this;
|
||||||
|
converse.connection.reset();
|
||||||
|
this.$('form').hide(function () {
|
||||||
|
$(this).replaceWith('<span class="spinner centered"/>');
|
||||||
|
if (that.fields.password && that.fields.username) {
|
||||||
|
// automatically log the user in
|
||||||
|
converse.connection.connect(
|
||||||
|
that.fields.username+'@'+that.domain,
|
||||||
|
that.fields.password,
|
||||||
|
converse.onConnect
|
||||||
|
);
|
||||||
|
converse.chatboxviews.get('controlbox')
|
||||||
|
.switchTab({target: that.$tabs.find('.current')})
|
||||||
|
.giveFeedback(__('Now logging you in'));
|
||||||
|
} else {
|
||||||
|
converse.chatboxviews.get('controlbox')
|
||||||
|
.renderLoginPanel()
|
||||||
|
.giveFeedback(__('Registered successfully'));
|
||||||
|
}
|
||||||
|
that.reset();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -4528,11 +4561,18 @@
|
|||||||
});
|
});
|
||||||
$form.append('<input type="submit" class="submit" value="'+__('Register')+'"/>');
|
$form.append('<input type="submit" class="submit" value="'+__('Register')+'"/>');
|
||||||
$form.append('<input type="button" class="submit" value="'+__('Cancel')+'"/>');
|
$form.append('<input type="button" class="submit" value="'+__('Cancel')+'"/>');
|
||||||
$form.on('submit', $.proxy(this.register, this));
|
$form.on('submit', $.proxy(this.onRegister, this));
|
||||||
$form.find('input[type=button]').on('click', $.proxy(this.cancel, this));
|
$form.find('input[type=button]').on('click', $.proxy(this.onCancel, this));
|
||||||
},
|
},
|
||||||
|
|
||||||
reportErrors: function (stanza) {
|
reportErrors: function (stanza) {
|
||||||
|
/* Report back to the user any error messages received from the
|
||||||
|
* XMPP server after attempted registration.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (XMLElement) stanza - The IQ stanza received from the
|
||||||
|
* XMPP server.
|
||||||
|
*/
|
||||||
var $form= this.$('form'), flash;
|
var $form= this.$('form'), flash;
|
||||||
var $errmsgs = $(stanza).find('error text');
|
var $errmsgs = $(stanza).find('error text');
|
||||||
var $flash = $form.find('.form-errors');
|
var $flash = $form.find('.form-errors');
|
||||||
@ -4559,11 +4599,22 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
cancel: function (ev) {
|
cancel: function (ev) {
|
||||||
|
/* Callback method, when the user cancels the registration
|
||||||
|
* form.
|
||||||
|
*/
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
alert('TBD'); // TODO
|
this.render(); // XXX: check if this works.
|
||||||
},
|
},
|
||||||
|
|
||||||
register: function (ev) {
|
onRegister: function (ev) {
|
||||||
|
/* Callback method, when the user submits the registration
|
||||||
|
* form.
|
||||||
|
* Provides form error feedback or starts the registration
|
||||||
|
* process.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (Event) ev - the submit event.
|
||||||
|
*/
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
var $empty_inputs = this.$('input:emptyVal');
|
var $empty_inputs = this.$('input:emptyVal');
|
||||||
if ($empty_inputs.length) {
|
if ($empty_inputs.length) {
|
||||||
@ -4578,13 +4629,39 @@
|
|||||||
$inputs.each(function () {
|
$inputs.each(function () {
|
||||||
iq.cnode(utils.webForm2xForm(this)).up();
|
iq.cnode(utils.webForm2xForm(this)).up();
|
||||||
});
|
});
|
||||||
converse.connection._addSysHandler(this._submit_cb.bind(this),
|
converse.connection._addSysHandler(this._onRegisterIQ.bind(this), null, "iq", null, null);
|
||||||
null, "iq", null, null);
|
|
||||||
converse.connection.send(iq);
|
converse.connection.send(iq);
|
||||||
|
this.setFields(iq.tree());
|
||||||
},
|
},
|
||||||
|
|
||||||
_submit_cb: function (stanza) {
|
setFields: function (stanza) {
|
||||||
var i, field, error = null,
|
/* Stores the values that will be sent to the XMPP server
|
||||||
|
* during attempted registration.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (XMLElement) stanza - the IQ stanza that will be sent to the XMPP server.
|
||||||
|
*/
|
||||||
|
var query = stanza.getElementsByTagName("query"), field, i;
|
||||||
|
if (query.length > 0) {
|
||||||
|
query = query[0];
|
||||||
|
$(query).find('field').each($.proxy(function (idx, field) {
|
||||||
|
var name = field.getAttribute('var').toLowerCase();
|
||||||
|
var value = $(field).children('value').text();
|
||||||
|
this.fields[name] = value;
|
||||||
|
converse.connection.register.fields[name] = value;
|
||||||
|
}, this));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_onRegisterIQ: function (stanza) {
|
||||||
|
/* Callback method that gets called when a return IQ stanza
|
||||||
|
* is received from the XMPP server, after attempting to
|
||||||
|
* register a new user.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (XMLElement) stanza - The IQ stanza.
|
||||||
|
*/
|
||||||
|
var i, field, error = null, that,
|
||||||
query = stanza.getElementsByTagName("query");
|
query = stanza.getElementsByTagName("query");
|
||||||
if (query.length > 0) {
|
if (query.length > 0) {
|
||||||
query = query[0];
|
query = query[0];
|
||||||
@ -4606,15 +4683,16 @@
|
|||||||
}
|
}
|
||||||
this.reportErrors(stanza);
|
this.reportErrors(stanza);
|
||||||
} else {
|
} else {
|
||||||
converse.log("Registered successfully.");
|
|
||||||
this.$('form').hide(function () {
|
|
||||||
$(this).remove(); // TODO What to render next?
|
|
||||||
});
|
|
||||||
converse.connection._changeConnectStatus(Strophe.Status.REGISTERED, null);
|
converse.connection._changeConnectStatus(Strophe.Status.REGISTERED, null);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reset: function () {
|
||||||
|
this.fields = {};
|
||||||
|
delete this.domain;
|
||||||
|
},
|
||||||
|
|
||||||
remove: function () {
|
remove: function () {
|
||||||
// XXX ?
|
// XXX ?
|
||||||
this.$tabs.empty();
|
this.$tabs.empty();
|
||||||
|
Loading…
Reference in New Issue
Block a user