Skip to content
Snippets Groups Projects
Commit 0fa1fcde authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Starting the migration of issue 1000 from feature branch to dev branch.

parent 5cc3406e
No related branches found
No related tags found
No related merge requests found
Showing with 211 additions and 18 deletions
......@@ -99,6 +99,7 @@ var dialog_js = und.flatten([
'/dialog/controllers/primary_user_provisioned.js',
'/dialog/controllers/generate_assertion.js',
'/dialog/controllers/is_this_your_computer.js',
'/dialog/controllers/set_password.js',
'/dialog/start.js'
]]);
......
......@@ -73,6 +73,15 @@ BrowserID.Modules.Actions = (function() {
if(onsuccess) onsuccess(null);
},
doSetPassword: function(info) {
startService("set_password", info);
},
doStageUser: function(info) {
var email = info.email;
bid.Helpers.Dialog.createUser.call(this, email);
},
doConfirmUser: function(info) {
startRegCheckService.call(this, info, "waitForUserValidation", "user_confirmed");
},
......
......@@ -61,7 +61,8 @@ BrowserID.Modules.Authenticate = (function() {
else if(info.known) {
enterPasswordState.call(self);
} else {
createSecondaryUserState.call(self);
self.close("new_user", { email: email });
//createSecondaryUserState.call(self);
}
}
}
......@@ -71,9 +72,10 @@ BrowserID.Modules.Authenticate = (function() {
email = getEmail();
if (email) {
dialogHelpers.createUser.call(self, email, callback);
self.close("new_user", { email: email });
//dialogHelpers.createUser.call(self, email, callback);
} else {
callback && callback();
complete(callback);
}
}
......
/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */
/*global _: true, 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.SetPassword = (function() {
"use strict";
var bid = BrowserID,
dom = bid.DOM,
complete = bid.Helpers.complete,
sc;
function submit(callback) {
var pass = dom.getInner("#password"),
vpass = dom.getInner("#vpassword");
var valid = bid.Validation.passwordAndValidationPassword(pass, vpass);
if(valid) {
this.close("password_set", { password: pass });
}
complete(callback, valid);
}
function cancel() {
this.close("cancel_state");
}
var Module = bid.Modules.PageModule.extend({
start: function(options) {
var self=this;
self.renderDialog("set_password");
self.click("#cancel", cancel);
sc.start.call(self, options);
},
submit: submit,
cancel: cancel
});
sc = Module.sc;
return Module;
}());
......@@ -93,6 +93,18 @@ BrowserID.State = (function() {
startAction("doAuthenticate", info);
});
handleState("new_user", function(msg, info) {
self.newUserEmail = info.email;
startAction("doSetPassword", info);
});
handleState("password_set", function(msg, info) {
info = info || {};
info.email = self.newUserEmail;
startAction("doStageUser", info);
});
handleState("user_staged", function(msg, info) {
self.stagedEmail = info.email;
info.required = !!requiredEmail;
......
......@@ -33,6 +33,7 @@
moduleManager.register("generate_assertion", modules.GenerateAssertion);
moduleManager.register("xhr_delay", modules.XHRDelay);
moduleManager.register("xhr_disable_form", modules.XHRDisableForm);
moduleManager.register("set_password", modules.SetPassword);
moduleManager.start("xhr_delay");
moduleManager.start("xhr_disable_form");
......
<!-- 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/. -->
<strong><%= gettext('Welcome to BrowserID!') %></strong>
<div class="form_section" id="set_password">
<ul class="inputs">
<li>
<%= gettext('This email looks new, so let&#39;s get you set up.') %>
</li>
<li>
<label for="password" class="serif"><%= gettext('Password') %></label>
<input id="password" class="sans" type="password" maxlength="80" />
<div class="tooltip" id="password_required" for="password">
<%= gettext('Password is required.') %>
</div>
<div class="tooltip" id="password_length" for="password">
<%= gettext('Password must be between 8 and 80 characters long.') %>
</div>
</li>
<li>
<label class="serif" for="vpassword"><%= gettext('Verify Password') %></label>
<input class="sans" id="vpassword" placeholder="<%= gettext('Repeat Password') %>" type="password" maxlength=80 />
<div class="tooltip" id="vpassword_required" for="vpassword">
<%= gettext('Verification password is required.') %>
</div>
<div class="tooltip" id="passwords_no_match" for="vpassword">
<%= gettext('Passwords do not match.') %>
</div>
</li>
</ul>
<div class="submit cf">
<button><%= gettext('verify email') %></button>
<a id="cancel" href="#"><%= gettext('cancel') %></a>
</div>
</div>
......@@ -52,6 +52,7 @@ BrowserID.Modules.PageModule = (function() {
start: function(options) {
var self=this;
self.bind("form", "submit", cancelEvent(onSubmit));
// TODO - why is this here and not in pick_email?
self.click("#thisIsNotMe", self.close.bind(self, "notme"));
},
......
......@@ -80,7 +80,7 @@
});
function testUserUnregistered() {
register("create_user", function() {
register("new_user", function() {
ok(true, "email was valid, user not registered");
start();
});
......@@ -88,14 +88,14 @@
controller.checkEmail();
}
asyncTest("checkEmail with unknown secondary email, expect 'create_user' message", function() {
asyncTest("checkEmail with unknown secondary email, expect 'new_user' message", function() {
$("#email").val("unregistered@testuser.com");
xhr.useResult("unknown_secondary");
testUserUnregistered();
});
asyncTest("checkEmail with email with leading/trailing whitespace, user not registered, expect 'create_user' message", function() {
asyncTest("checkEmail with email with leading/trailing whitespace, user not registered, expect 'new_user' message", function() {
$("#email").val(" unregistered@testuser.com ");
xhr.useResult("unknown_secondary");
......@@ -165,8 +165,8 @@
$("#email").val("unregistered@testuser.com");
xhr.useResult("unknown_secondary");
register("user_staged", function(msg, info) {
equal(info.email, "unregistered@testuser.com", "user_staged with correct email triggered");
register("new_user", function(msg, info) {
equal(info.email, "unregistered@testuser.com", "new_user with correct email triggered");
start();
});
......@@ -177,27 +177,28 @@
$("#email").val("unregistered");
var handlerCalled = false;
register("user_staged", function(msg, info) {
register("new_user", function(msg, info) {
handlerCalled = true;
});
controller.createUser(function() {
equal(handlerCalled, false, "bad jiji, user_staged should not have been called with invalid email");
equal(handlerCalled, false, "bad jiji, new_user should not have been called with invalid email");
start();
});
});
/*
asyncTest("createUser with valid email but throttling", function() {
$("#email").val("unregistered@testuser.com");
var handlerCalled = false;
register("user_staged", function(msg, info) {
register("new_user", function(msg, info) {
handlerCalled = true;
});
xhr.useResult("throttle");
controller.createUser(function() {
equal(handlerCalled, false, "bad jiji, user_staged should not have been called with throttling");
equal(handlerCalled, false, "bad jiji, new_user should not have been called with throttling");
equal(bid.Tooltip.shown, true, "tooltip is shown");
start();
});
......@@ -207,16 +208,16 @@
$("#email").val("unregistered@testuser.com");
var handlerCalled = false;
register("user_staged", function(msg, info) {
register("new_user", function(msg, info) {
handlerCalled = true;
});
xhr.useResult("ajaxError");
controller.createUser(function() {
equal(handlerCalled, false, "bad jiji, user_staged should not have been called with XHR error");
equal(handlerCalled, false, "bad jiji, new_user should not have been called with XHR error");
start();
});
});
*/
}());
/*jshint browsers:true, forin: true, laxbreak: true */
/*global test: true, start: true, stop: true, module: true, ok: true, equal: true, BrowserID: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/. */
(function() {
"use strict";
var controller,
el = $("body"),
bid = BrowserID,
testHelpers = bid.TestHelpers,
register = testHelpers.register,
controller;
function createController(options) {
controller = bid.Modules.SetPassword.create();
controller.start(options);
}
module("controllers/set_password", {
setup: function() {
testHelpers.setup();
createController();
},
teardown: function() {
controller.destroy();
testHelpers.teardown();
}
});
test("create - show correct template", function() {
ok($("#set_password").length, "set_password template added");
});
asyncTest("submit with good password/vpassword - password_set message raised", function() {
$("#password").val("password");
$("#vpassword").val("password");
var password;
register("password_set", function(msg, info) {
password = info.password;
});
controller.submit(function() {
ok(password, "password", "password_set message raised with correct password");
start();
});
});
asyncTest("cancel - cancel_state message raised", function() {
register("cancel_state", function(msg, info) {
ok(true, "state cancelled");
start();
});
$("#cancel").click();
});
}());
......@@ -78,10 +78,21 @@
equal(error, "start: controller must be specified", "creating a state machine without a controller fails");
});
test("new_user - call doSetPassword with correct email", function() {
mediator.publish("new_user", { email: TEST_EMAIL });
equal(actions.info.doSetPassword.email, TEST_EMAIL, "correct email sent to doSetPassword");
});
test("password_set - call doStageUser with correct email", function() {
mediator.publish("new_user", { email: TEST_EMAIL });
mediator.publish("password_set");
equal(actions.info.doStageUser.email, TEST_EMAIL, "correct email sent to doStageUser");
});
test("user_staged - call doConfirmUser", function() {
mediator.publish("user_staged", {
email: TEST_EMAIL
});
mediator.publish("user_staged", { email: TEST_EMAIL });
equal(actions.info.doConfirmUser.email, TEST_EMAIL, "waiting for email confirmation for testuser@testuser.com");
});
......
......@@ -126,6 +126,7 @@
<script src="/dialog/controllers/provision_primary_user.js"></script>
<script src="/dialog/controllers/primary_user_provisioned.js"></script>
<script src="/dialog/controllers/is_this_your_computer.js"></script>
<script src="/dialog/controllers/set_password.js"></script>
<script src="/pages/page_helpers.js"></script>
<script src="/pages/add_email_address.js"></script>
......@@ -185,6 +186,7 @@
<script src="cases/controllers/provision_primary_user.js"></script>
<script src="cases/controllers/primary_user_provisioned.js"></script>
<script src="cases/controllers/is_this_your_computer.js"></script>
<script src="cases/controllers/set_password.js"></script>
<!-- must go last or all other tests will fail. -->
<script src="cases/controllers/dialog.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment