Merge pull request #283 from mozilla/reconfig-how-it-should-be

Reconfig how it should be
This commit is contained in:
ckarlof 2014-01-17 11:09:19 -08:00
Родитель 504400ecff 9fb38977ad
Коммит 6004baaad4
11 изменённых файлов: 142 добавлений и 65 удалений

Просмотреть файл

@ -62,7 +62,6 @@ module.exports = function (grunt) {
grunt.task.run([
'clean:server',
'selectconfig:app',
'preprocess-config',
'concurrent:server',
'autoprefixer',
'serverproc:app'
@ -82,7 +81,6 @@ module.exports = function (grunt) {
'clean:dist',
'useminPrepare',
'selectconfig:dist',
'preprocess-config',
'requirejs',
'concurrent:dist',
'autoprefixer',

Просмотреть файл

@ -6,8 +6,6 @@
define([], function () {
return {
FXA_ACCOUNT_SERVER: '/* @echo fxaccountUrl */',
// All browsers have a max length of URI that they can handle.
// IE8 has the shortest total length at 2083 bytes and 2048 characters
// for GET requests.

Просмотреть файл

@ -10,42 +10,68 @@
define([
'fxaClient',
'processed/constants'
'jquery'
],
function (FxaClient, Constants) {
function (FxaClient, $) {
var client;
function FxaClientWrapper() {
this.client = new FxaClient(Constants.FXA_ACCOUNT_SERVER);
// nothing to do here.
}
FxaClientWrapper.prototype = {
_getClientAsync: function () {
var defer = $.Deferred();
if (client) {
defer.resolve(client);
} else {
$.getJSON('/config', function (data) {
client = new FxaClient(data.fxaccountUrl);
defer.resolve(client);
});
}
return defer.promise();
},
signIn: function (email, password) {
return this.client.signIn(email, password, { keys: true });
return this._getClientAsync().then(function (client) {
return client.signIn(email, password, { keys: true });
});
},
signUp: function (email, password) {
return this.client
.signUp(email, password)
.then(function () {
// when a user signs up, sign them in immediately
return this.signIn(email, password, { keys: true });
}.bind(this));
return this._getClientAsync().then(function (client) {
return client.signUp(email, password, { keys: true })
.then(function () {
return client.signIn(email, password, { keys: true });
});
});
},
verifyCode: function (uid, code) {
return this.client.verifyCode(uid, code);
return this._getClientAsync().then(function (client) {
return client.verifyCode(uid, code);
});
},
requestPasswordReset: function (email) {
return this.client.passwordForgotSendCode(email);
return this._getClientAsync().then(function (client) {
return client.passwordForgotSendCode(email);
});
},
completePasswordReset: function (email, newPassword, token, code) {
return this.client.passwordForgotVerifyCode(code, token)
.then(function (result) {
return this.client.accountReset(email,
newPassword,
result.accountResetToken);
}.bind(this));
return this._getClientAsync().then(function (client) {
return client.passwordForgotVerifyCode(code, token)
.then(function (result) {
return client.accountReset(email,
newPassword,
result.accountResetToken);
});
});
}
};

Просмотреть файл

@ -8,7 +8,7 @@
define([
'underscore',
'processed/constants'
'lib/constants'
],
function(_, Constants) {
return {

Просмотреть файл

@ -10,7 +10,7 @@ require.config({
jquery: '../bower_components/jquery/jquery',
backbone: '../bower_components/backbone/backbone',
underscore: '../bower_components/underscore/underscore',
gherkin: '../bower_components/fxa-js-client-old/web/bundle',
fxaClient: '../bower_components/fxa-js-client/fxa-client',
text: '../bower_components/requirejs-text/text',
mustache: '../bower_components/mustache/mustache',
stache: '../bower_components/requirejs-mustache/stache',
@ -50,7 +50,8 @@ require([
'../tests/setup',
'../tests/spec/lib/channels/fx-desktop',
'../tests/spec/lib/xss',
'../tests/spec/lib/url'
'../tests/spec/lib/url',
'../tests/spec/lib/fxa-client'
],
function (Mocha) {
var runner = Mocha.run();

Просмотреть файл

@ -0,0 +1,85 @@
/* 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/. */
'use strict';
define([
'mocha',
'chai',
'jquery',
'lib/fxa-client'
],
function (mocha, chai, $, FxaClientWrapper) {
/*global beforeEach, describe, it*/
var assert = chai.assert;
var email;
var password = 'password';
var client;
describe('lib/fxa-client', function () {
beforeEach(function () {
client = new FxaClientWrapper();
email = 'testuser' + Math.random() + '@testuser.com';
});
describe('signUp', function () {
it('signs up a user with email/password', function (done) {
client.signUp(email, password)
.then(function () {
assert.isTrue(true);
done();
}, function (err) {
assert.fail(err);
done();
});
});
});
describe('signIn', function () {
it('signs a user in with email/password', function (done) {
client.signUp(email, password)
.then(function () {
client.signIn(email, password)
.then(function () {
assert.isTrue(true);
done();
}, function (err) {
assert.fail(err);
done();
});
}, function (err) {
assert.fail(err);
done();
});
});
});
describe('verifyCode', function () {
});
describe('requestPasswordReset', function () {
it('requests a password reset', function (done) {
client.signUp(email, password)
.then(function () {
client.signIn(email, password)
.then(function () {
client.requestPasswordReset(email)
.then(function () {
assert.isTrue(true);
done();
}, function (err) {
assert.fail(err);
done();
});
});
});
});
});
describe('completePasswordReset', function () {
});
});
});

Просмотреть файл

@ -10,7 +10,7 @@ define([
'chai',
'underscore',
'lib/url',
'processed/constants'
'lib/constants'
],
function (mocha, chai, _, Url, Constants) {
var assert = chai.assert;

Просмотреть файл

@ -10,7 +10,7 @@ define([
'chai',
'underscore',
'lib/xss',
'processed/constants'
'lib/constants'
],
function (mocha, chai, _, XSS, Constants) {
var assert = chai.assert;

Просмотреть файл

@ -1,37 +0,0 @@
/* 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/. */
module.exports = function (grunt) {
'use strict';
grunt.task.registerTask(
'preprocess-config',
'preprocess client side configuration',
function() {
// Correct configuration will be loaded based
// on process.env.CONFIG_FILES when the selectconfig task is run. If
// selectconfig is not run, local.json will be used by default.
var config = require('../server/lib/configuration');
var context = {
fxaccountUrl: config.get('fxaccount_url')
};
grunt.config('preprocess', {
js: {
src: '<%= yeoman.app %>/scripts/preprocess/constants.js',
dest: '<%= yeoman.app %>/scripts/processed/constants.js',
options: {
context: context
}
}
});
grunt.task.run(['preprocess']);
}
);
};

Просмотреть файл

@ -11,6 +11,12 @@ module.exports = function(app) {
res.redirect(req.originalUrl.slice(3));
});
app.get('/config', function(req, res) {
res.json({
fxaccountUrl: config.get('fxaccount_url')
});
});
// handle email verification links
app.get('/v1/verify_email', function(req, res) {
res.redirect(req.originalUrl.slice(3));

Просмотреть файл

@ -17,7 +17,7 @@ define([
var email;
registerSuite({
name: 'password_reset',
name: 'reset_password',
setup: function () {
email = 'signin' + Math.random() + '@example.com';