2014-10-02 16:05:44 -04:00
|
|
|
'use strict';
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2015-02-20 11:55:11 -05:00
|
|
|
var LoginInitialCtrl = function($scope, $location, $routeParams, $q, newsletter, email, auth, publickeyVerifier) {
|
2014-11-19 14:54:59 -05:00
|
|
|
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-11-19 14:54:59 -05:00
|
|
|
var emailAddress = auth.emailAddress;
|
2014-11-12 10:12:26 -05:00
|
|
|
|
|
|
|
var termsMsg = 'You must accept the Terms of Service to continue.',
|
|
|
|
states = {
|
|
|
|
IDLE: 1,
|
|
|
|
PROCESSING: 2,
|
|
|
|
DONE: 3
|
|
|
|
};
|
2013-10-23 11:17:36 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
$scope.state.ui = states.IDLE; // initial state
|
|
|
|
|
|
|
|
//
|
|
|
|
// scope functions
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Continue to key import screen
|
|
|
|
*/
|
|
|
|
$scope.importKey = function() {
|
2014-11-12 10:12:26 -05:00
|
|
|
if (!$scope.agree) {
|
|
|
|
displayError(new Error(termsMsg));
|
2014-10-02 16:05:44 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-04-15 11:43:33 -04:00
|
|
|
|
2014-11-12 10:12:26 -05:00
|
|
|
$scope.errMsg = undefined;
|
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
// sing up to newsletter
|
2014-11-12 10:12:26 -05:00
|
|
|
newsletter.signup(emailAddress, $scope.newsletter);
|
2014-10-02 16:05:44 -04:00
|
|
|
// 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() {
|
2014-11-12 10:12:26 -05:00
|
|
|
if (!$scope.agree) {
|
|
|
|
displayError(new Error(termsMsg));
|
2014-10-02 16:05:44 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-07-31 13:08:21 -04:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
// sing up to newsletter
|
2014-11-12 10:12:26 -05:00
|
|
|
newsletter.signup(emailAddress, $scope.newsletter);
|
2014-10-02 16:05:44 -04:00
|
|
|
// go to set keygen screen
|
|
|
|
$scope.setState(states.PROCESSING);
|
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
return $q(function(resolve) {
|
2014-12-17 07:32:12 -05:00
|
|
|
$scope.errMsg = undefined;
|
2014-12-16 10:14:16 -05:00
|
|
|
resolve();
|
2014-12-17 07:32:12 -05:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
}).then(function() {
|
|
|
|
// generate key without passphrase
|
|
|
|
return email.unlock({
|
2015-01-20 06:55:19 -05:00
|
|
|
realname: auth.realname,
|
2014-12-16 10:14:16 -05:00
|
|
|
passphrase: undefined
|
2014-10-02 16:05:44 -04:00
|
|
|
});
|
2014-12-16 10:14:16 -05:00
|
|
|
|
2015-02-20 11:55:11 -05:00
|
|
|
}).then(function(keypair) {
|
|
|
|
// go to public key verification
|
|
|
|
publickeyVerifier.keypair = keypair;
|
|
|
|
$location.path('/login-verify-public-key');
|
2014-12-16 10:14:16 -05:00
|
|
|
|
|
|
|
}).catch(displayError);
|
2014-10-02 16:05:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setState = function(state) {
|
|
|
|
$scope.state.ui = state;
|
2013-10-21 07:10:42 -04:00
|
|
|
};
|
2014-11-12 10:12:26 -05:00
|
|
|
|
|
|
|
function displayError(err) {
|
|
|
|
$scope.setState(states.IDLE);
|
|
|
|
$scope.errMsg = err.errMsg || err.message;
|
|
|
|
}
|
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;
|