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

93 lines
2.2 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
var LoginInitialCtrl = function($scope, $location, $routeParams, newsletter) {
2014-10-02 16:05:44 -04:00
if (!appController._emailDao && !$routeParams.dev) {
$location.path('/'); // init app
return;
}
if (appController._emailDao) {
var emailDao = appController._emailDao,
emailAddress = emailDao._account.emailAddress;
}
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() {
if (!$scope.agree) {
displayError(new Error(termsMsg));
2014-10-02 16:05:44 -04:00
return;
}
$scope.errMsg = undefined;
2014-10-02 16:05:44 -04:00
// sing up to newsletter
newsletter.signup(emailAddress, $scope.newsletter);
2014-10-02 16:05:44 -04:00
// 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.agree) {
displayError(new Error(termsMsg));
2014-10-02 16:05:44 -04:00
return;
}
$scope.errMsg = undefined;
2014-10-02 16:05:44 -04:00
// sing up to newsletter
newsletter.signup(emailAddress, $scope.newsletter);
2014-10-02 16:05:44 -04:00
// go to set keygen screen
$scope.setState(states.PROCESSING);
emailDao.unlock({
passphrase: undefined // generate key without passphrase
}, function(err) {
if (err) {
displayError(err);
return;
}
appController._auth.storeCredentials(function(err) {
2014-10-02 16:05:44 -04:00
if (err) {
displayError(err);
2014-10-02 16:05:44 -04:00
return;
}
2014-09-12 11:11:05 -04:00
$location.path('/desktop');
$scope.$apply();
2014-10-02 16:05:44 -04:00
});
});
2014-10-02 16:05:44 -04:00
};
$scope.setState = function(state) {
$scope.state.ui = state;
2013-10-21 07:10:42 -04:00
};
function displayError(err) {
$scope.setState(states.IDLE);
$scope.errMsg = err.errMsg || err.message;
$scope.$apply();
}
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;