1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-15 13:45:08 -05:00
mail/src/js/controller/login-initial.js

119 lines
2.9 KiB
JavaScript
Raw Normal View History

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-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-10-02 16:05:44 -04:00
// sing up to newsletter
$scope.signUpToNewsletter();
// go to key import
$location.path('/login-new-device');
};
2014-10-02 16:05:44 -04:00
/**
* Continue to keygen
*/
$scope.generateKey = function() {
if (!$scope.state.agree) {
$scope.onError({
message: termsMsg
});
return;
}
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);
}
};
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;