From 83a98f963e147f03e045ca6983800ede1a79bc6f Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Wed, 14 Dec 2011 15:11:15 +0000
Subject: [PATCH] Fix "cancel" in the forgot password screen when accessed via
 required email.

close #754.
---
 resources/static/dialog/controllers/dialog.js      |  5 ++---
 resources/static/dialog/resources/state_machine.js | 14 +++++++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/resources/static/dialog/controllers/dialog.js b/resources/static/dialog/controllers/dialog.js
index eef6fa57d..380932446 100644
--- a/resources/static/dialog/controllers/dialog.js
+++ b/resources/static/dialog/controllers/dialog.js
@@ -64,7 +64,7 @@ BrowserID.Modules.Dialog = (function() {
       email: email,
       verifier: verifier,
       verificationMessage: message
-    }); 
+    });
     controller.startCheck();
   }
 
@@ -245,8 +245,7 @@ BrowserID.Modules.Dialog = (function() {
         user.checkAuthenticationAndSync(function onSuccess() {},
           function onComplete(authenticated) {
             if (self.requiredEmail) {
-              // XXX get this out of here and into the state machine!
-              self.doAuthenticateWithRequiredEmail({
+              self.publish("authenticate_with_required_email", {
                 email: self.requiredEmail,
                 authenticated: authenticated
               });
diff --git a/resources/static/dialog/resources/state_machine.js b/resources/static/dialog/resources/state_machine.js
index eb0f56596..93704afaa 100644
--- a/resources/static/dialog/resources/state_machine.js
+++ b/resources/static/dialog/resources/state_machine.js
@@ -55,7 +55,7 @@
     var args = [].slice.call(arguments, 1),
         controller = this.controller;
 
-    // Remember the state and the information for the state in case we have to 
+    // Remember the state and the information for the state in case we have to
     // go back to it.
     stateStack.push({
       funcName: funcName,
@@ -65,7 +65,7 @@
     controller[funcName].apply(controller, args);
   }
 
-  // Used for when the current state is being cancelled and the user wishes to 
+  // Used for when the current state is being cancelled and the user wishes to
   // go to the previous state.
   function popState() {
     // Skip the first state, it is where the user is at now.
@@ -85,7 +85,7 @@
         controller = self.controller,
         gotoState = pushState.bind(self),
         cancelState = popState.bind(self);
-       
+
     subscribe("offline", function(msg, info) {
       gotoState("doOffline");
     });
@@ -102,6 +102,10 @@
       gotoState("doEmailConfirmed");
     });
 
+    subscribe("authenticate_with_required_email", function(msg, info) {
+      gotoState("doAuthenticateWithRequiredEmail", info);
+    });
+
     subscribe("pick_email", function() {
       gotoState("doPickEmail");
     });
@@ -161,7 +165,7 @@
   }
 
   var StateMachine = BrowserID.Class({
-    init: function() { 
+    init: function() {
       // empty
     },
 
@@ -169,7 +173,7 @@
       options = options || {};
       this.controller = options.controller;
       startStateMachine.call(this);
-    }, 
+    },
 
     stop: function() {
       unsubscribeAll();
-- 
GitLab