From 32d4f41ec3598461159a97d1ca1ef069eb307cd5 Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Sat, 28 Jul 2012 14:05:34 +0100
Subject: [PATCH] Generalize the logic for checking the redirect if
 authenticated paths.

---
 resources/static/pages/js/start.js | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/resources/static/pages/js/start.js b/resources/static/pages/js/start.js
index daa811f4c..9297dc6b2 100644
--- a/resources/static/pages/js/start.js
+++ b/resources/static/pages/js/start.js
@@ -18,7 +18,7 @@ $(function() {
       xhr = bid.XHR,
       network = bid.Network,
       token = pageHelpers.getParameterByName("token"),
-      path = document.location.pathname,
+      path = document.location.pathname || "/",
       moduleManager = bid.module,
       modules = bid.Modules,
       CookieCheck = modules.CookieCheck,
@@ -26,7 +26,8 @@ $(function() {
       XHRDisableForm = modules.XHRDisableForm,
       Development = modules.Development,
       ANIMATION_TIME = 500,
-      checkCookiePaths = [ "/signin", "/signup", "/forgot", "/add_email_address", "/confirm", "/verify_email_address" ];
+      checkCookiePaths = [ "/signin", "/forgot", "/add_email_address", "/confirm", "/verify_email_address" ],
+      redirectIfAuthenticatedPaths = [ "/signin", "/forgot" ];
 
 
   function shouldCheckCookies(path) {
@@ -38,6 +39,7 @@ $(function() {
     }
   }
 
+
   // Firefox and IE have rendering bugs where if the box-sizing is set to
   // border-box and a min-height is set, padding is added on top of the
   // min-height, making elements render using the normal W3C box model.  Use
@@ -131,23 +133,23 @@ $(function() {
     if (!status) return;
 
     user.checkAuthentication(function(authenticated) {
-      if (!path || path === "/") {
+      // If the user is authenticated and the path should not be allowed if the
+      // user is authenticated, redirect them back to the main page. See issue
+      // #1345 https://github.com/mozilla/browserid/issues/1345
+      if (authenticated && _.indexOf(redirectIfAuthenticatedPaths, path) > -1) {
+        document.location = "/";
+        return;
+      }
+      else if (path === "/") {
         bid.index();
       }
       else if (path === "/signin") {
-        if (authenticated) {
-          document.location = "/";
-          return;
-        }
         var module = bid.signIn.create();
         module.start({});
       }
       else if (path === "/forgot") {
-        if (authenticated) {
-          document.location = "/";
-          return;
-        }
-        bid.forgot();
+        var module = bid.forgot.create();
+        module.start({});
       }
       // START TRANSITION CODE
       // add_email_address has been renamed to confirm. Once all outstanding
-- 
GitLab