diff --git a/browserid/static/dialog/controllers/addemail_controller.js b/browserid/static/dialog/controllers/addemail_controller.js new file mode 100644 index 0000000000000000000000000000000000000000..fb1b67a8cb8e871343af8897e9e213b69331c9e1 --- /dev/null +++ b/browserid/static/dialog/controllers/addemail_controller.js @@ -0,0 +1,42 @@ +(function() { + "use strict"; + + PageController.extend("addemail", {}, { + init: function(options) { + this._super({ + bodyTemplate: "addemail.ejs", + bodyVars: { + sitename: BrowserIDNetwork.origin, + identities: getEmails() + }, + footerTemplate: "bottom-addemail.ejs", + footerVars: {} + }); + // select the first option + this.find('input:first').attr('checked', true); + }, + + submit: function() { + // add the actual email + // now we need to actually try to stage the creation of this account. + var email = $("#email_input").val(); + var keypair = CryptoStubs.genKeyPair(); + + // kick the user to waiting/status page while we talk to the server. + this.doWait(BrowserIDWait.addEmail); + + var self = this; + BrowserIDNetwork.addEmail(email, keypair, function() { + // email successfully staged, now wait for email confirmation + self.close("addemail:complete", { + email: email, + keypair: keypair + }); + }, + function() { + self.runErrorDialog(BrowserIDErrors.addEmail); + }); + } + }); + +}()); diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index fb20f2c52fc1f0f03fa8602d709be7f0627893b1..fb210b1921c735171355dbbb36eb9a2896756f5e 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -24,26 +24,6 @@ PageController.extend("Dialog", {}, { this.doAuthenticate(); }, - "#addemail_button click": function(event) { - // add the actual email - // now we need to actually try to stage the creation of this account. - var email = $("#email_input").val(); - var keypair = CryptoStubs.genKeyPair(); - - var self = this; - - // kick the user to waiting/status page while we talk to the server. - this.doWait(BrowserIDWait.addEmail); - - BrowserIDNetwork.addEmail(email, keypair, function() { - // email successfully staged, now wait for email confirmation - self.doConfirmEmail(email, keypair); - }, - function() { - self.runErrorDialog(BrowserIDErrors.addEmail); - }); - }, - getVerifiedEmail: function(origin_url, onsuccess, onerror) { this.onsuccess = onsuccess; this.onerror = onerror; @@ -91,13 +71,17 @@ PageController.extend("Dialog", {}, { }); hub.subscribe("chooseemail:addemail", function() { - self.doNewEmail(); + self.doAddEmail(); }); hub.subscribe("chooseemail:notme", function() { self.doNotMe(); }); + hub.subscribe("addemail:complete", function(msg, info) { + self.doConfirmEmail(info.email, info.keypair); + }); + hub.subscribe("start", function() { self.doStart(); }); @@ -146,14 +130,8 @@ PageController.extend("Dialog", {}, { this.element.forgotpassword(); }, - doWait: function(info) { - this.renderTemplates("wait.ejs", {title: info.message, message: info.description}); - }, - - doNewEmail: function() { - this.renderTemplates("addemail.ejs", {}, - "bottom-addemail.ejs", {}); - + doAddEmail: function() { + this.element.addemail(); }, doConfirmEmail: function(email, keypair) { diff --git a/browserid/static/dialog/dialog.js b/browserid/static/dialog/dialog.js index 8c3c19ce271bf7b2ec34f41e2b94c79359cd1803..5ac3581f1af28ba9f7bad62e1ff2358b5b8fe189 100644 --- a/browserid/static/dialog/dialog.js +++ b/browserid/static/dialog/dialog.js @@ -26,7 +26,8 @@ steal.plugins( 'createaccount', 'checkregistration', 'forgotpassword', - 'chooseemail') // loads files in controllers folder + 'chooseemail', + 'addemail') // loads files in controllers folder .views('authenticate.ejs', 'addemail.ejs',