2014-10-02 16:05:44 -04:00
|
|
|
'use strict';
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var appController = require('../app-controller');
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var LoginInitialCtrl = function($scope, $location, $routeParams) {
|
|
|
|
if (!appController._emailDao && !$routeParams.dev) {
|
|
|
|
$location.path('/'); // init app
|
|
|
|
return;
|
|
|
|
}
|
2014-08-13 10:16:28 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var emailDao = appController._emailDao,
|
|
|
|
states, termsMsg = 'You must accept the Terms of Service to continue.';
|
2013-10-23 11:17:36 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
states = {
|
|
|
|
IDLE: 1,
|
|
|
|
PROCESSING: 2,
|
|
|
|
DONE: 3
|
|
|
|
};
|
|
|
|
$scope.state.ui = states.IDLE; // initial state
|
|
|
|
|
|
|
|
//
|
|
|
|
// scope functions
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Continue to key import screen
|
|
|
|
*/
|
|
|
|
$scope.importKey = function() {
|
|
|
|
if (!$scope.state.agree) {
|
|
|
|
$scope.onError({
|
|
|
|
message: termsMsg
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2014-04-15 11:43:33 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
// sing up to newsletter
|
|
|
|
$scope.signUpToNewsletter();
|
|
|
|
// go to key import
|
|
|
|
$location.path('/login-new-device');
|
|
|
|
};
|
2014-03-05 14:14:23 -05:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
/**
|
|
|
|
* Continue to keygen
|
|
|
|
*/
|
|
|
|
$scope.generateKey = function() {
|
|
|
|
if (!$scope.state.agree) {
|
|
|
|
$scope.onError({
|
|
|
|
message: termsMsg
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2014-07-31 13:08:21 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
// sing up to newsletter
|
|
|
|
$scope.signUpToNewsletter();
|
|
|
|
// go to set keygen screen
|
|
|
|
$scope.setState(states.PROCESSING);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
emailDao.unlock({
|
|
|
|
passphrase: undefined // generate key without passphrase
|
|
|
|
}, function(err) {
|
|
|
|
if (err) {
|
|
|
|
$scope.setState(states.IDLE);
|
|
|
|
$scope.onError(err);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
appController._auth.storeCredentials(function(err) {
|
2014-09-12 11:11:05 -04:00
|
|
|
if (err) {
|
2014-10-02 16:05:44 -04:00
|
|
|
return $scope.onError(err);
|
2014-09-12 11:11:05 -04:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
$location.path('/desktop');
|
|
|
|
$scope.$apply();
|
2014-09-12 11:11:05 -04:00
|
|
|
});
|
2014-10-02 16:05:44 -04:00
|
|
|
});
|
|
|
|
}, 500);
|
|
|
|
};
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
/**
|
|
|
|
* [signUpToNewsletter description]
|
|
|
|
* @param {Function} callback (optional)
|
|
|
|
*/
|
|
|
|
$scope.signUpToNewsletter = function(callback) {
|
|
|
|
if (!$scope.state.newsletter) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var address = emailDao._account.emailAddress;
|
|
|
|
var uri = 'https://whiteout.us8.list-manage.com/subscribe/post?u=52ea5a9e1be9e1d194f184158&id=6538e8f09f';
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var formData = new FormData();
|
|
|
|
formData.append('EMAIL', address);
|
|
|
|
formData.append('b_52ea5a9e1be9e1d194f184158_6538e8f09f', '');
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('post', uri, true);
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
xhr.onload = function() {
|
|
|
|
if (callback) {
|
|
|
|
callback(null, xhr);
|
|
|
|
}
|
2014-07-31 15:39:43 -04:00
|
|
|
};
|
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
xhr.onerror = function(err) {
|
|
|
|
if (callback) {
|
|
|
|
callback(err);
|
|
|
|
}
|
2013-11-11 11:56:51 -05:00
|
|
|
};
|
2014-10-02 16:05:44 -04:00
|
|
|
|
|
|
|
xhr.send(formData);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setState = function(state) {
|
|
|
|
$scope.state.ui = state;
|
2013-10-21 07:10:42 -04:00
|
|
|
};
|
2014-10-02 16:05:44 -04:00
|
|
|
};
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-10-08 06:34:34 -04:00
|
|
|
module.exports = LoginInitialCtrl;
|