1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

Merge pull request #104 from whiteout-io/dev/WO-498

[WO-498] Add newsletter signup
This commit is contained in:
Felix Hammerl 2014-08-04 18:30:55 +02:00
commit d278afb253
5 changed files with 139 additions and 3 deletions

View File

@ -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/

View File

@ -37,6 +37,10 @@ textarea {
-moz-osx-font-smoothing: grayscale;
}
fieldset {
border: 1px solid $color-grey-lighter;
}
// Basic layout
.main-app-view {
height: 100%;

View File

@ -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;
}
}
}
}

View File

@ -9,11 +9,16 @@
<p><b>PGP key.</b> 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.</p>
<form>
<div class="terms">
<div class="option terms">
<input type="checkbox" ng-model="state.agree" id="cb-agree">
<label for="cb-agree">I agree to the Whiteout Networks <a href="https://whiteout.io/terms.html" target="_blank">Terms of Service</a> and have read the <a href="https://whiteout.io/privacy-service.html" target="_blank">Privacy Policy</a>.</label>
</div>
<div class="option newsletter">
<input type="checkbox" ng-model="state.newsletter" id="cb-newsletter">
<label for="cb-newsletter">Stay up to date on Whiteout Networks products and important announcements.</label>
</div>
<div>
<button wo-touch="importKey()" class="btn btn-alt">Import existing key</button>
<button type="submit" wo-touch="setPassphrase()" class="btn"tabindex="3">Generate new key</button>

View File

@ -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();
});