From 6ce1f2361a2788794414589a785f51256002e652 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 31 Jul 2014 21:39:43 +0200 Subject: [PATCH] [WO-498] Add newsletter signup --- src/js/controller/login-initial.js | 46 +++++++++++++++++++ src/sass/_scaffolding.scss | 4 ++ src/sass/views/_login.scss | 17 ++++++- src/tpl/login-initial.html | 7 ++- test/unit/login-initial-ctrl-test.js | 68 ++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/src/js/controller/login-initial.js b/src/js/controller/login-initial.js index 103da70..02c896d 100644 --- a/src/js/controller/login-initial.js +++ b/src/js/controller/login-initial.js @@ -19,6 +19,9 @@ define(function(require) { // scope functions // + /** + * Continue to key import screen + */ $scope.importKey = function() { if (!$scope.state.agree) { $scope.onError({ @@ -27,9 +30,15 @@ define(function(require) { return; } + // sing up to newsletter + $scope.signUpToNewsletter(); + // go to key import $location.path('/login-new-device'); }; + /** + * Continue to set passphrase screen for keygen + */ $scope.setPassphrase = function() { if (!$scope.state.agree) { $scope.onError({ @@ -38,9 +47,46 @@ define(function(require) { return; } + // sing up to newsletter + $scope.signUpToNewsletter(); + // go to set passphrase screen $scope.setState(states.SET_PASSPHRASE); }; + /** + * [signUpToNewsletter description] + * @param {Function} callback (optional) + */ + $scope.signUpToNewsletter = function(callback) { + if (!$scope.state.newsletter) { + return; + } + + var address = emailDao._account.emailAddress; + var uri = 'https://whiteout.us8.list-manage.com/subscribe/post?u=52ea5a9e1be9e1d194f184158&id=6538e8f09f'; + + var formData = new FormData(); + formData.append('EMAIL', address); + formData.append('b_52ea5a9e1be9e1d194f184158_6538e8f09f', ''); + + var xhr = new XMLHttpRequest(); + xhr.open('post', uri, true); + + xhr.onload = function() { + if (callback) { + callback(null, xhr); + } + }; + + xhr.onerror = function(err) { + if (callback) { + callback(err); + } + }; + + xhr.send(formData); + }; + /* * Taken from jQuery validate.password plug-in 1.0 * http://bassistance.de/jquery-plugins/jquery-plugin-validate.password/ diff --git a/src/sass/_scaffolding.scss b/src/sass/_scaffolding.scss index dac7522..ac8a627 100755 --- a/src/sass/_scaffolding.scss +++ b/src/sass/_scaffolding.scss @@ -37,6 +37,10 @@ textarea { -moz-osx-font-smoothing: grayscale; } +fieldset { + border: 1px solid $color-grey-lighter; +} + // Basic layout .main-app-view { height: 100%; diff --git a/src/sass/views/_login.scss b/src/sass/views/_login.scss index 8129dce..eeaa48a 100644 --- a/src/sass/views/_login.scss +++ b/src/sass/views/_login.scss @@ -119,8 +119,21 @@ .view-login-initial { .content { - .terms { - margin-bottom: 40px; + form { + .option { + width: 90%; + font-size: $font-size-small; + margin: 0 auto; + } + + .terms { + margin-top: 30px; + margin-bottom: 15px; + } + + .newsletter { + margin-bottom: 40px; + } } } } diff --git a/src/tpl/login-initial.html b/src/tpl/login-initial.html index e60e30e..4d1c7ab 100644 --- a/src/tpl/login-initial.html +++ b/src/tpl/login-initial.html @@ -9,11 +9,16 @@

PGP key. You can either import an existing PGP key or generate a new one. Your private key remains on your device and is not sent to our servers.

-
+
+ +
diff --git a/test/unit/login-initial-ctrl-test.js b/test/unit/login-initial-ctrl-test.js index ea569ab..4e0d70d 100644 --- a/test/unit/login-initial-ctrl-test.js +++ b/test/unit/login-initial-ctrl-test.js @@ -62,12 +62,69 @@ define(function(require) { }); }); + describe('signUpToNewsletter', function() { + var xhrMock, requests; + + beforeEach(function() { + xhrMock = sinon.useFakeXMLHttpRequest(); + requests = []; + + xhrMock.onCreate = function(xhr) { + requests.push(xhr); + }; + }); + + afterEach(function() { + xhrMock.restore(); + }); + + it('should not signup', function() { + scope.state.newsletter = false; + + scope.signUpToNewsletter(); + expect(requests.length).to.equal(0); + }); + + it('should fail', function(done) { + scope.state.newsletter = true; + + scope.signUpToNewsletter(function(err, xhr) { + expect(err).to.exist; + expect(xhr).to.not.exist; + done(); + }); + + expect(requests.length).to.equal(1); + requests[0].onerror('err'); + }); + + it('should work without callback', function() { + scope.state.newsletter = true; + + scope.signUpToNewsletter(); + + expect(requests.length).to.equal(1); + requests[0].respond(200, { + "Content-Type": "text/plain" + }, 'foobar!'); + }); + }); + describe('go to import key', function() { + var signUpToNewsletterStub; + beforeEach(function() { + signUpToNewsletterStub = sinon.stub(scope, 'signUpToNewsletter'); + }); + afterEach(function() { + signUpToNewsletterStub.restore(); + }); + it('should not continue if terms are not accepted', function(done) { scope.state.agree = undefined; scope.onError = function(err) { expect(err.message).to.contain('Terms'); + expect(signUpToNewsletterStub.called).to.be.false; done(); }; @@ -77,6 +134,7 @@ define(function(require) { it('should work', function() { scope.state.agree = true; scope.importKey(); + expect(signUpToNewsletterStub.calledOnce).to.be.true; expect(location.$$path).to.equal('/login-new-device'); }); }); @@ -124,11 +182,20 @@ define(function(require) { }); describe('setPassphrase', function() { + var signUpToNewsletterStub; + beforeEach(function() { + signUpToNewsletterStub = sinon.stub(scope, 'signUpToNewsletter'); + }); + afterEach(function() { + signUpToNewsletterStub.restore(); + }); + it('should not continue if terms are not accepted', function(done) { scope.state.agree = undefined; scope.onError = function(err) { expect(err.message).to.contain('Terms'); + expect(signUpToNewsletterStub.called).to.be.false; done(); }; @@ -140,6 +207,7 @@ define(function(require) { var setStateStub = sinon.stub(scope, 'setState', function(state) { expect(setStateStub.calledOnce).to.be.true; + expect(signUpToNewsletterStub.calledOnce).to.be.true; expect(state).to.equal(2); done(); });