diff --git a/converse.js b/converse.js index b29b23674..055eb0023 100644 --- a/converse.js +++ b/converse.js @@ -4498,7 +4498,7 @@ connect_cb(req, callback, raw); } else { if (this.getRegistrationFields(req, callback, raw)) { - delete this._registering; + this._registering = false; } } }, this); @@ -4529,8 +4529,9 @@ } if (register.length === 0) { conn._changeConnectStatus( - Strophe.Status.REGIFAIL, - 'Sorry, the given provider does not support in band account registration. Please try with a different provider.'); + Strophe.Status.REGIFAIL, + __('Sorry, the given provider does not support in band account registration. Please try with a different provider.') + ); return true; } // Send an IQ stanza to get all required data fields @@ -4588,9 +4589,10 @@ return; } $form.find('input[type=submit]').hide() - .after('') - .after('') - .after('
Requesting a registration form from the XMPP server
'); + .after(converse.templates.registration_request({ + cancel: __('Cancel'), + info_message: __('Requesting a registration form from the XMPP server') + })); $form.find('button.cancel').on('click', $.proxy(this.cancelRegistration, this)); this.reset({ domain: Strophe.getDomainFromJid(domain), @@ -4613,7 +4615,9 @@ if (_.contains([ Strophe.Status.DISCONNECTED, Strophe.Status.CONNFAIL, - Strophe.Status.REGIFAIL + Strophe.Status.REGIFAIL, + Strophe.Status.NOTACCEPTABLE, + Strophe.Status.CONFLICT ], status)) { converse.log('Problem during registration: Strophe.Status is: '+status); @@ -4622,16 +4626,10 @@ this.giveFeedback(error, 'error'); } else { this.giveFeedback(__( - 'Something went wrong establishing a connection with "%1$s". Are you sure it exists?', + 'Something went wrong while establishing a connection with "%1$s". Are you sure it exists?', this.domain ), 'error'); } - } else if (status == Strophe.Status.CONFLICT) { - // TODO - converse.log('CONFLICT'); - } else if (status == Strophe.Status.NOTACCEPTABLE) { - // TODO - converse.log('NOTACCEPTABLE'); } else if (status == Strophe.Status.REGISTERED) { converse.log("Registered successfully."); converse.connection.reset(); @@ -4694,9 +4692,9 @@ }, this)); } if (this.fields) { - $form.append(''); + $form.append(''); $form.on('submit', $.proxy(this.submitRegistrationForm, this)); - $form.append(''); + $form.append(''); $form.find('input[type=button]').on('click', $.proxy(this.cancelRegistration, this)); } else { $form.append(''); diff --git a/main.js b/main.js index 00fa0b75a..a0adcc38f 100644 --- a/main.js +++ b/main.js @@ -110,6 +110,7 @@ require.config({ "register_panel": "src/templates/register_panel", "register_tab": "src/templates/register_tab", "registration_form": "src/templates/registration_form", + "registration_request": "src/templates/registration_request", "requesting_contact": "src/templates/requesting_contact", "requesting_contacts": "src/templates/requesting_contacts", "room_description": "src/templates/room_description", diff --git a/spec/register.js b/spec/register.js index 1d1a8e9d9..907cfc252 100644 --- a/spec/register.js +++ b/spec/register.js @@ -11,12 +11,27 @@ describe("The Registration Panel", $.proxy(function (mock, test_utils) { beforeEach(function () { + test_utils.closeControlBox(); + connection = mock.mock_connection; + connection.connected = false; + converse._tearDown(); + converse.initialize({ + bosh_service_url: 'localhost', + allow_registration: true, + auto_subscribe: false, + animate: false, + connection: connection, + no_trimming: true, + debug: true + }); test_utils.openControlBox(); + }); - afterEach(function () { + afterEach($.proxy(function () { + this.connection.connected = false; test_utils.closeControlBox(); - }); + }, converse)); it("is not available unless allow_registration=true", $.proxy(function () { test_utils.closeControlBox(); @@ -61,6 +76,9 @@ var $panels = cbview.$('.controlbox-panes'); var $login = $panels.children().first(); var $registration = $panels.children().last(); + expect($tabs.find('li').first().text()).toBe('Sign in'); + expect($tabs.find('li').last().text()).toBe('Register'); + spyOn(cbview, 'switchTab').andCallThrough(); cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called $tabs.find('li').last().find('a').click(); // Click the Register tab @@ -94,7 +112,50 @@ }, converse)); it("will render a registration form as received from the XMPP provider", $.proxy(function () { - // TODO + var cbview = this.chatboxviews.get('controlbox'); + cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab + var registerview = this.chatboxviews.get('controlbox').registerpanel; + spyOn(registerview, 'onProviderChosen').andCallThrough(); + spyOn(registerview, 'getRegistrationFields').andCallThrough(); + spyOn(registerview, 'onRegistrationFields').andCallThrough(); + spyOn(registerview, 'renderRegistrationForm').andCallThrough(); + registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called + spyOn(this.connection, 'connect').andCallThrough(); + + expect(registerview._registering).toBeFalsy(); + expect(this.connection.connected).toBeFalsy(); + registerview.$('input[name=domain]').val('conversejs.org'); + registerview.$('input[type=submit]').click(); + expect(registerview.onProviderChosen).toHaveBeenCalled(); + expect(registerview._registering).toBeTruthy(); + expect(this.connection.connect).toHaveBeenCalled(); + + var stanza = new Strophe.Builder("stream:features", { + 'xmlns:stream': "http://etherx.jabber.org/streams", + 'xmlns': "jabber:client" + }) + .c('register', {xmlns: "http://jabber.org/features/iq-register"}).up() + .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}); + this.connection._connect_cb(test_utils.createRequest(stanza)); + + expect(registerview.getRegistrationFields).toHaveBeenCalled(); + expect(this.connection.connected).toBeTruthy(); + + stanza = $iq({ + 'type': 'result', + 'id': 'reg1' + }).c('query', {'xmlns': 'jabber:iq:register'}) + .c('instructions') + .t('Please choose a username, password and provide your email address').up() + .c('username').up() + .c('password').up() + .c('email'); + this.connection._dataRecv(test_utils.createRequest(stanza)); + expect(registerview.onRegistrationFields).toHaveBeenCalled(); + expect(registerview.renderRegistrationForm).toHaveBeenCalled(); + expect(registerview.$('input').length).toBe(5); + expect(registerview.$('input[type=submit]').length).toBe(1); + expect(registerview.$('input[type=button]').length).toBe(1); }, converse)); }, converse, mock, test_utils)); diff --git a/src/templates.js b/src/templates.js index 0145ce062..598e0b0f7 100644 --- a/src/templates.js +++ b/src/templates.js @@ -35,6 +35,7 @@ define("converse-templates", [ "tpl!register_panel", "tpl!register_tab", "tpl!registration_form", + "tpl!registration_request", "tpl!requesting_contact", "tpl!requesting_contacts", "tpl!room_description", @@ -86,18 +87,19 @@ define("converse-templates", [ register_panel: arguments[33], register_tab: arguments[34], registration_form: arguments[35], - requesting_contact: arguments[36], - requesting_contacts: arguments[37], - room_description: arguments[38], - room_item: arguments[39], - room_panel: arguments[40], - roster: arguments[41], - roster_item: arguments[42], - search_contact: arguments[43], - select_option: arguments[44], - status_option: arguments[45], - toggle_chats: arguments[46], - toolbar: arguments[47], - trimmed_chat: arguments[48] + registration_request: arguments[36], + requesting_contact: arguments[37], + requesting_contacts: arguments[38], + room_description: arguments[39], + room_item: arguments[40], + room_panel: arguments[41], + roster: arguments[42], + roster_item: arguments[43], + search_contact: arguments[44], + select_option: arguments[45], + status_option: arguments[46], + toggle_chats: arguments[47], + toolbar: arguments[48], + trimmed_chat: arguments[49] }; }); diff --git a/src/templates/registration_request.html b/src/templates/registration_request.html new file mode 100644 index 000000000..036d4b844 --- /dev/null +++ b/src/templates/registration_request.html @@ -0,0 +1,3 @@ + +{{info_message}}
+