From e891a52859cad45137b3b136d3dcb4636442cd1e Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Wed, 14 Mar 2012 15:09:06 -0600
Subject: [PATCH] begin integrating new .ejs screen 'is_this_your_computer'

---
 lib/static_resources.js                       |  1 +
 .../static/dialog/controllers/actions.js      |  4 +++
 .../controllers/is_this_your_computer.js      | 32 +++++++++++++++++++
 resources/static/dialog/resources/state.js    | 12 ++++++-
 resources/static/dialog/start.js              |  2 +-
 .../dialog/views/is_this_your_computer.ejs    |  9 ++++--
 resources/static/shared/network.js            | 10 ++++++
 resources/static/shared/storage.js            |  8 ++---
 8 files changed, 69 insertions(+), 9 deletions(-)
 create mode 100644 resources/static/dialog/controllers/is_this_your_computer.js

diff --git a/lib/static_resources.js b/lib/static_resources.js
index 6ef48a3f3..cc6e73dd2 100644
--- a/lib/static_resources.js
+++ b/lib/static_resources.js
@@ -94,6 +94,7 @@ var dialog_js = und.flatten([
     '/dialog/controllers/provision_primary_user.js',
     '/dialog/controllers/primary_user_provisioned.js',
     '/dialog/controllers/email_chosen.js',
+    '/dialog/controllers/is_this_your_computer.js',
 
     '/dialog/start.js'
   ]]);
diff --git a/resources/static/dialog/controllers/actions.js b/resources/static/dialog/controllers/actions.js
index 320877daf..334bcbd15 100644
--- a/resources/static/dialog/controllers/actions.js
+++ b/resources/static/dialog/controllers/actions.js
@@ -151,6 +151,10 @@ BrowserID.Modules.Actions = (function() {
       startService("primary_user_provisioned", info);
     },
 
+    doIsThisYourComputer: function(info) {
+      startService("is_this_your_computer", info);
+    },
+
     doEmailChosen: function(info) {
       startService("email_chosen", info);
     }
diff --git a/resources/static/dialog/controllers/is_this_your_computer.js b/resources/static/dialog/controllers/is_this_your_computer.js
new file mode 100644
index 000000000..6f5bef2d0
--- /dev/null
+++ b/resources/static/dialog/controllers/is_this_your_computer.js
@@ -0,0 +1,32 @@
+/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */
+/*global BrowserID:true, PageController: true */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+BrowserID.Modules.IsThisYourComputer = (function() {
+  "use strict";
+
+  var bid = BrowserID,
+      user = bid.User,
+      network = bid.Network,
+      storage = bid.Storage,
+      errors = bid.Errors;
+
+  var Module = bid.Modules.PageModule.extend({
+    start: function(options) {
+      options = options || {};
+
+      var self = this,
+          complete = function(status) {
+            options.ready && options.ready(status || false);
+          };
+
+      self.renderDialog("is_this_your_computer", options);
+
+      Module.sc.start.call(self, options);
+    }
+  });
+
+  return Module;
+
+}());
diff --git a/resources/static/dialog/resources/state.js b/resources/static/dialog/resources/state.js
index 746cda91e..d6f431159 100644
--- a/resources/static/dialog/resources/state.js
+++ b/resources/static/dialog/resources/state.js
@@ -6,6 +6,7 @@
 BrowserID.State = (function() {
   var bid = BrowserID,
       storage = bid.Storage,
+      network = bid.Network,
       mediator = bid.Mediator,
       helpers = bid.Helpers,
       publish = mediator.publish.bind(mediator),
@@ -77,12 +78,21 @@ BrowserID.State = (function() {
         });
       }
       else if (authenticated) {
-        publish("pick_email");
+        if (storage.usersComputer.confirmed(network.userid())) {
+          publish("pick_email");
+        } else {
+          publish("is_this_your_computer");
+        }
       } else {
         publish("authenticate");
       }
     });
 
+    subscribe("is_this_your_computer", function(msg, info) {
+      startState("doIsThisYourComputer", info);
+    });
+
+
     subscribe("authenticate", function(msg, info) {
       info = info || {};
       info.privacyURL = self.privacyURL;
diff --git a/resources/static/dialog/start.js b/resources/static/dialog/start.js
index 8768ea7ac..970034d1a 100644
--- a/resources/static/dialog/start.js
+++ b/resources/static/dialog/start.js
@@ -24,6 +24,7 @@
       moduleManager.register("authenticate", modules.Authenticate);
       moduleManager.register("check_registration", modules.CheckRegistration);
       moduleManager.register("forgot_password", modules.ForgotPassword);
+      moduleManager.register("is_this_your_computer", modules.IsThisYourComputer);
       moduleManager.register("pick_email", modules.PickEmail);
       moduleManager.register("required_email", modules.RequiredEmail);
       moduleManager.register("verify_primary_user", modules.VerifyPrimaryUser);
@@ -33,7 +34,6 @@
       moduleManager.register("xhr_delay", modules.XHRDelay);
       moduleManager.register("xhr_disable_form", modules.XHRDisableForm);
 
-
       moduleManager.start("xhr_delay");
       moduleManager.start("xhr_disable_form");
       moduleManager.start("dialog");
diff --git a/resources/static/dialog/views/is_this_your_computer.ejs b/resources/static/dialog/views/is_this_your_computer.ejs
index abbf01120..730eab32a 100644
--- a/resources/static/dialog/views/is_this_your_computer.ejs
+++ b/resources/static/dialog/views/is_this_your_computer.ejs
@@ -2,15 +2,18 @@
       License, v. 2.0. If a copy of the MPL was not distributed with this
       file, You can obtain one at http://mozilla.org/MPL/2.0/. */ %>
 
-    <h2><%= gettext('If you don't mind me asking, is this your computer?') %></h2>
+    <h2><%= gettext('If you don\'t mind me asking, is this your computer?') %></h2>
 
     <p>
       <button class="this_is_my_computer" tabindex="3"><%= gettext('yes') %></button>
-      <%= gettext('If so, we'll keep you logged in for a couple weeks') %>
+      <%= gettext('If so, we\'ll keep you logged in for a couple weeks') %>
     </p>
 
     <p>
       <button class="this_is_not_my_computer" tabindex="3"><%= gettext('no') %></button>
-      <%= gettext('If you're at a public computer such as a library or internet cafe, we'll ask you ' +
+      <%= gettext('If you\'re at a public computer such as a library or internet cafe, we\'ll ask you ' +
                   'for your password again in five minutes.') %>
     </p>
+
+
+
diff --git a/resources/static/shared/network.js b/resources/static/shared/network.js
index 333f8a9d3..013a36d61 100644
--- a/resources/static/shared/network.js
+++ b/resources/static/shared/network.js
@@ -524,6 +524,16 @@ BrowserID.Network = (function() {
       });
     },
 
+    /**
+     * Return the user's userid, which will an integer if the user
+     * is authenticated, undefined otherwise.
+     *
+     * @method userid
+     */
+    userid: function() {
+      return userid;
+    },
+
     /**
      * Get the current time on the server in the form of a
      * date object.
diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js
index ca85182b5..1d6bc4f5c 100644
--- a/resources/static/shared/storage.js
+++ b/resources/static/shared/storage.js
@@ -320,20 +320,20 @@ BrowserID.Storage = (function() {
 
     usersComputer: {
       /** Query whether the user has confirmed that this is their computer
-       * @param {string} userid - the user's numeric id, returned from session_context when authed.
+       * @param {integer} userid - the user's numeric id, returned from session_context when authed.
        * @method usersComputer.confirmed */
       confirmed: userConfirmedOnComputer,
       /** Save the fact that a user confirmed that this is their computer
-       * @param {string} userid - the user's numeric id, returned from session_context when authed.
+       * @param {integer} userid - the user's numeric id, returned from session_context when authed.
        * @method usersComputer.setConfirmed */
       setConfirmed: setUserConfirmedOnComputer,
       /** Query whether a user has been "seen" on this computer before
-       * @param {string} userid - the user's numeric id, returned from session_context when authed.
+       * @param {integer} userid - the user's numeric id, returned from session_context when authed.
        * @method usersComputer.seen */
       seen: userSeenOnComputer,
       /** Save the fact that a user has been seen on this computer before, but do not overwrite
        *  existing state
-       * @param {string} userid - the user's numeric id, returned from session_context when authed.
+       * @param {integer} userid - the user's numeric id, returned from session_context when authed.
        * @method usersComputer.setSeen */
       setSeen: setUserSeenOnComputer
     },
-- 
GitLab