mail/src/js/controller/login-initial.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-10-21 07:10:42 -04:00
define(function(require) {
'use strict';
2013-10-23 11:17:36 -04:00
var appController = require('js/app-controller'),
dl = require('js/util/download');
2013-10-21 07:10:42 -04:00
var LoginInitialCtrl = function($scope, $location) {
2013-10-23 11:17:36 -04:00
var emailDao = appController._emailDao,
states;
$scope.states = states = {
IDLE: 1,
PROCESSING: 2,
DONE: 4
};
$scope.state = states.IDLE; // initial state
//
// scope functions
//
2013-10-21 07:10:42 -04:00
$scope.confirmPassphrase = function() {
var passphrase = $scope.passphrase,
2013-10-23 11:17:36 -04:00
confirmation = $scope.confirmation;
2013-10-21 07:10:42 -04:00
if (!passphrase || passphrase !== confirmation) {
return;
}
2013-10-23 11:17:36 -04:00
setState(states.PROCESSING);
setTimeout(function() {
emailDao.unlock({}, passphrase, function(err) {
if (err) {
console.error(err);
setState(states.IDLE, true);
return;
}
2013-10-21 07:10:42 -04:00
2013-10-23 11:17:36 -04:00
setState(states.DONE, true);
});
}, 500);
};
2013-10-21 07:10:42 -04:00
2013-10-23 11:17:36 -04:00
$scope.exportKeypair = function() {
// export keys from keychain
emailDao._crypto.exportKeys(function(err, keys) {
2013-10-21 07:10:42 -04:00
if (err) {
console.error(err);
return;
}
2013-10-23 11:17:36 -04:00
var id = keys.keyId.substring(8, keys.keyId.length);
dl.createDownload(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain');
$scope.exported = true;
});
};
$scope.proceed = function() {
// login to imap backend
appController._emailDao.imapLogin(function(err) {
if (err) {
console.error(err);
return;
}
onLogin();
});
2013-10-21 07:10:42 -04:00
};
function onLogin() {
$location.path('/desktop');
$scope.$apply();
}
2013-10-23 11:17:36 -04:00
function setState(state, async) {
$scope.state = state;
if (async) {
$scope.$apply();
}
}
2013-10-21 07:10:42 -04:00
};
return LoginInitialCtrl;
2013-10-23 11:17:36 -04:00
});