diff --git a/browserid/static/dialog/controllers/chooseemail_controller.js b/browserid/static/dialog/controllers/chooseemail_controller.js new file mode 100644 index 0000000000000000000000000000000000000000..cb883f58d3d8ed985e7b92d7923f331b96abc5e7 --- /dev/null +++ b/browserid/static/dialog/controllers/chooseemail_controller.js @@ -0,0 +1,35 @@ +(function() { + "use strict"; + + PageController.extend("Chooseemail", {}, { + init: function(options) { + this._super({ + bodyTemplate: "signin.ejs", + bodyVars: { + sitename: BrowserIDNetwork.origin, + identities: getEmails() + }, + footerTemplate: "bottom-pickemail.ejs", + footerVars: {} + }); + // select the first option + this.find('input:first').attr('checked', true); + }, + + submit: function() { + var email = $("#identities input:checked").val(); + this.close("chooseemail:complete", { + email: email + }); + }, + + "#addemail click": function(event) { + this.close("chooseemail:addemail"); + }, + + "#notme click": function(event) { + this.close("chooseemail:notme"); + } + }); + +}()); diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index da7f322d57f09efedfa38e0b439669b492d1872f..504b397eb7b39af432b05fa85bac4b79b871a660 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -24,27 +24,6 @@ PageController.extend("Dialog", {}, { this.doAuthenticate(); }, - "#pickemail click": function(event) { - var email = $("#identities input:checked").val(); - - // yay! now we need to produce an assertion. - var storedID = getEmails()[email]; - - var privkey = storedID.priv; - var issuer = storedID.issuer; - var audience = BrowserIDNetwork.origin; - var assertion = CryptoStubs.createAssertion(audience, email, privkey, issuer); - // Clear onerror before the call to onsuccess - the code to onsuccess - // calls window.close, which would trigger the onerror callback if we - // tried this afterwards. - this.onerror = null; - this.onsuccess(assertion); - }, - - "#addemail click": function(event) { - this.doNewEmail(); - }, - "#addemail_button click": function(event) { // add the actual email // now we need to actually try to stage the creation of this account. @@ -65,11 +44,6 @@ PageController.extend("Dialog", {}, { }); }, - "#notme click": function(event) { - clearEmails(); - BrowserIDNetwork.logout(this.doAuthenticate.bind(this)); - }, - "#cancel click": function(event) { this.onerror("canceled"); }, @@ -97,7 +71,7 @@ PageController.extend("Dialog", {}, { stateMachine: function() { var self=this, hub = OpenAjax.hub, el = this.element; - hub.subscribe("createaccount:created", function(info) { + hub.subscribe("createaccount:created", function(msg, info) { self.doConfirmEmail(info.email, info.keypair); }); @@ -114,17 +88,25 @@ PageController.extend("Dialog", {}, { }); hub.subscribe("checkregistration:confirmed", function() { - // this is a secondary registration from browserid.org, persist - // email, keypair, and that fact - self.persistAddressAndKeyPair(self.confirmEmail, - self.confirmKeypair, "browserid.org:443"); - self.syncidentities(); + self.doRegistrationConfirmed(); }); hub.subscribe("checkregistration:complete", function() { self.doSignIn(); }); + hub.subscribe("chooseemail:complete", function(msg, info) { + self.doEmailSelected(info.email); + }); + + hub.subscribe("chooseemail:addemail", function() { + self.doNewEmail(); + }); + + hub.subscribe("chooseemail:notme", function() { + self.doNotMe(); + }); + hub.subscribe("cancel", function() { // cancel if(self.onerror) { @@ -153,11 +135,7 @@ PageController.extend("Dialog", {}, { }, doSignIn: function() { - this.renderTemplates("signin.ejs", {sitename: BrowserIDNetwork.origin, identities: getEmails()}, - "bottom-pickemail.ejs", {}); - - // select the first option - this.find('input:first').attr('checked', true); + this.element.chooseemail(); }, doAuthenticate: function() { @@ -189,6 +167,37 @@ PageController.extend("Dialog", {}, { this.element.checkregistration({email: email}); }, + doRegistrationConfirmed: function() { + var self = this; + // this is a secondary registration from browserid.org, persist + // email, keypair, and that fact + self.persistAddressAndKeyPair(self.confirmEmail, + self.confirmKeypair, "browserid.org:443"); + self.syncidentities(); + + }, + + doEmailSelected: function(email) { + var self=this, + // yay! now we need to produce an assertion. + storedID = getEmails()[email], + privkey = storedID.priv, + issuer = storedID.issuer, + audience = BrowserIDNetwork.origin, + assertion = CryptoStubs.createAssertion(audience, email, privkey, issuer); + + // Clear onerror before the call to onsuccess - the code to onsuccess + // calls window.close, which would trigger the onerror callback if we + // tried this afterwards. + self.onerror = null; + self.onsuccess(assertion); + }, + + doNotMe: function() { + clearEmails(); + BrowserIDNetwork.logout(this.doAuthenticate.bind(this)); + }, + persistAddressAndKeyPair: function(email, keypair, issuer) { var new_email_obj= { created: new Date(), diff --git a/browserid/static/dialog/dialog.js b/browserid/static/dialog/dialog.js index ac61d495a10358578f34d625b5a6ec0950f5d934..8c3c19ce271bf7b2ec34f41e2b94c79359cd1803 100644 --- a/browserid/static/dialog/dialog.js +++ b/browserid/static/dialog/dialog.js @@ -25,7 +25,8 @@ steal.plugins( 'authenticate', 'createaccount', 'checkregistration', - 'forgotpassword') // loads files in controllers folder + 'forgotpassword', + 'chooseemail') // loads files in controllers folder .views('authenticate.ejs', 'addemail.ejs', diff --git a/browserid/static/dialog/views/bottom-pickemail.ejs b/browserid/static/dialog/views/bottom-pickemail.ejs index debe989ff1c3cb8865cb52cead510c6f58a5a59e..b1cf8b5133ab88f7825ae323079587497eb4fba0 100644 --- a/browserid/static/dialog/views/bottom-pickemail.ejs +++ b/browserid/static/dialog/views/bottom-pickemail.ejs @@ -1,2 +1,2 @@ - <button id="pickemail" class="righty action submit">Sign In</button> + <input type="submit" id="pickemail" class="righty action submit" value="Sign In" /> <button id="cancel" class="righty">Cancel</button> diff --git a/browserid/static/dialog/views/signin.ejs b/browserid/static/dialog/views/signin.ejs index 0fda9e7e17dbe370938da09d634787c02b2efcb3..25519d6ec68f1e732d0b9149226d23da75e27f33 100644 --- a/browserid/static/dialog/views/signin.ejs +++ b/browserid/static/dialog/views/signin.ejs @@ -1,12 +1,10 @@ <div class="content"> <p class="prompt">What email address would you like to use to sign into <span class="sitename bad"><%= sitename %></span>?</p> - <form id="identities" name="identities"> - <ul> - <% _.each(identities, function(email_obj, email_address) { %> - <li><input type="radio" name="identity" value="<%=email_address%>" id="<%=email_address%>" /><label for="<%=email_address%>"><%= email_address %></label></li> - <% }); %> - </ul> - </form> + <ul id="identities"> + <% _.each(identities, function(email_obj, email_address) { %> + <li><input type="radio" name="identity" value="<%=email_address%>" id="<%=email_address%>" /><label for="<%=email_address%>"><%= email_address %></label></li> + <% }); %> + </ul> </div> <div class="actions"> <div class="action"><a id="addemail" href="#">Add a new email address</a></div>