diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index a7b56f623d3355b972d3d17b2c2f9045d4cd0bd3..9972682bdbd4f7b8b522a8ac473e35195fa4c508 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -1,5 +1,5 @@ /*jshint browser:true, jQuery: true, forin: true, laxbreak:true */ -/*global BrowserIDIdentities: true, BrowserIDNetwork: true, BrowserIDWait:true, BrowserIDErrors: true, PageController: true */ +/*global BrowserIDIdentities: true, BrowserIDWait:true, BrowserIDErrors: true, PageController: true */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -37,10 +37,7 @@ (function() { "use strict"; - // XXX - Push what we can of BrowserIDNetwork into BrowserIDIdentities. - var ANIMATION_TIME = 250, - network = BrowserIDNetwork, identities = BrowserIDIdentities; function animateSwap(fadeOutSelector, fadeInSelector, callback) { @@ -102,7 +99,7 @@ // XXX verify email length/format here // show error message if bad. - network.emailRegistered(email, function onComplete(registered) { + identities.emailRegistered(email, function onComplete(registered) { // XXX instead of using jQuery here, think about using CSS animations. $(".start").fadeOut(function() { if(registered) { @@ -175,7 +172,7 @@ resetPassword: function() { var email = $("#email").val(); var me=this; - network.requestPasswordReset(email, function(reset) { + identities.requestPasswordReset(email, function(reset) { if (reset) { me.close("reset_password", { email: email diff --git a/browserid/static/dialog/resources/browserid-identities.js b/browserid/static/dialog/resources/browserid-identities.js index 9ad54efc210429907fa8c7cf1a64535f45a37dd0..96331a4f14c255aa8efc260e64c48807620026d1 100644 --- a/browserid/static/dialog/resources/browserid-identities.js +++ b/browserid/static/dialog/resources/browserid-identities.js @@ -176,6 +176,17 @@ var BrowserIDIdentities = (function() { network.setPassword(password, onSuccess, onFailure); }, + /** + * Request a password reset for the given email address. + * @method requestPasswordReset + * @param {string} email - email address to reset password for. + * @param {function} [onSuccess] - Callback to call when complete. + * @param {function} [onFailure] - Called on XHR failure. + */ + requestPasswordReset: function(email, onSuccess, onFailure) { + network.requestPasswordReset(email, onSuccess, onFailure); + }, + /** * Cancel the current user's account. Remove last traces of their * identity. @@ -370,6 +381,19 @@ var BrowserIDIdentities = (function() { }, onFailure); }, + /** + * Check whether the email is already registered. + * @method emailRegistered + * @param {string} email - Email address to check. + * @param {function} [onSuccess] - Called with one boolean parameter when + * complete. Parameter is true if `email` is already registered, false + * otw. + * @param {function} [onFailure] - Called on XHR failure. + */ + emailRegistered: function(email, onSuccess, onFailure) { + network.emailRegistered(email, onSuccess, onFailure); + }, + /** * Add an email address to an already created account. Sends address and * keypair to the server, user then needs to verify account ownership. This diff --git a/browserid/static/dialog/test/qunit/browserid-identities_unit_test.js b/browserid/static/dialog/test/qunit/browserid-identities_unit_test.js index b0705048f60cbc8e090d23a2f2803e1118e19588..2c28ac31b45465aa046835d2822f61634dfa8dee 100644 --- a/browserid/static/dialog/test/qunit/browserid-identities_unit_test.js +++ b/browserid/static/dialog/test/qunit/browserid-identities_unit_test.js @@ -75,6 +75,10 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/browserid-iden onSuccess(credentialsValid); }, + emailRegistered: function(email, onSuccess, onFailure) { + onSuccess(email === "registered"); + }, + addEmail: function(email, origin, onSuccess, onFailure) { onSuccess(true); }, @@ -120,6 +124,10 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/browserid-iden onSuccess(); }, + requestPasswordReset: function(email, onSuccess, onFailure) { + onSuccess(true); + }, + cancelUser: function(onSuccess) { onSuccess(); }, @@ -189,6 +197,16 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/browserid-iden stop(); }); + test("requestPasswordReset", function() { + lib.requestPasswordReset("address", function(reset) { + // XXX fill this in. + ok(true); + start(); + }); + + stop(); + }); + test("confirmEmail on staged identity", function() { lib.createUser("testuser@testuser.com", function(keypair) { lib.confirmEmail("testuser@testuser.com", function() { @@ -347,6 +365,17 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/browserid-iden }); + test("emailRegistered with registered email", function() { + lib.emailRegistered("registered", function(registered) { + ok(registered); + start(); + }, function onFailure() { + ok(false); + start(); + }); + + stop(); + }); test("addEmail", function() { lib.addEmail("testemail@testemail.com", function(keypair) {