diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 504b397eb7b39af432b05fa85bac4b79b871a660..fb20f2c52fc1f0f03fa8602d709be7f0627893b1 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -44,26 +44,17 @@ PageController.extend("Dialog", {}, { }); }, - "#cancel click": function(event) { - this.onerror("canceled"); - }, - - "#back click": function(event) { - this.doStart(); - }, - getVerifiedEmail: function(origin_url, onsuccess, onerror) { this.onsuccess = onsuccess; this.onerror = onerror; + BrowserIDNetwork.setOrigin(origin_url); + this.doStart(); - var me=this; + + var self=this; $(window).bind("unload", function() { - // In the success case, me.onerror will have been cleared before unload - // is triggered. - if (me.onerror) { - me.onerror("canceled"); - } + self.doCancel(); }); }, @@ -107,11 +98,12 @@ PageController.extend("Dialog", {}, { self.doNotMe(); }); + hub.subscribe("start", function() { + self.doStart(); + }); + hub.subscribe("cancel", function() { - // cancel - if(self.onerror) { - self.onerror("cancelled"); - } + self.doCancel(); }); }, @@ -126,14 +118,18 @@ PageController.extend("Dialog", {}, { this.doSignIn(); } else { // do we even need to authenticate? - this.checkAuth(function() { - self.syncIdentities(); - }, function() { - self.doAuthenticate(); - }); + this.doCheckAuth(); } }, + doCancel: function() { + var self=this; + // cancel + if(self.onerror) { + self.onerror("cancelled"); + } + }, + doSignIn: function() { this.element.chooseemail(); }, @@ -243,14 +239,15 @@ PageController.extend("Dialog", {}, { }, - checkAuth: function(authcb, notauthcb) { + + doCheckAuth: function() { this.doWait(BrowserIDWait.checkAuth); BrowserIDNetwork.checkAuth(function(authenticated) { - if (!authenticated) { - notauthcb(); + if (authenticated) { + self.syncIdentities(); } else { - authcb(); + self.doAuthenticate(); } }, function() { self.runErrorDialog(BrowserIDErrors.checkAuthentication); diff --git a/browserid/static/dialog/controllers/page_controller.js b/browserid/static/dialog/controllers/page_controller.js index defa9d0ea7581515332585d537f2b53b2af74efc..8fd92ca2b9d40df084dd6297b788911ff9bb709f 100644 --- a/browserid/static/dialog/controllers/page_controller.js +++ b/browserid/static/dialog/controllers/page_controller.js @@ -84,8 +84,14 @@ "#cancel click": function() { this.close("cancel"); + }, + + "#back click": function(event) { + this.close("start"); } + + }); function setupEnterKey() {