2013-10-21 07:10:42 -04:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var appController = require('js/app-controller');
|
|
|
|
|
|
|
|
var LoginExistingCtrl = function($scope, $location) {
|
2013-10-22 08:37:32 -04:00
|
|
|
$scope.buttonEnabled = true;
|
|
|
|
|
2013-10-21 07:10:42 -04:00
|
|
|
$scope.confirmPassphrase = function() {
|
|
|
|
var passphrase = $scope.passphrase,
|
|
|
|
emailDao = appController._emailDao;
|
|
|
|
|
|
|
|
if (!passphrase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-22 08:37:32 -04:00
|
|
|
// disable button once loggin has started
|
|
|
|
$scope.buttonEnabled = false;
|
2013-10-21 07:10:42 -04:00
|
|
|
unlockCrypto(imapLogin);
|
|
|
|
|
|
|
|
function unlockCrypto(callback) {
|
|
|
|
var userId = emailDao._account.emailAddress;
|
|
|
|
emailDao._keychain.getUserKeyPair(userId, function(err, keypair) {
|
|
|
|
if (err) {
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emailDao.unlock(keypair, passphrase, callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function imapLogin(err) {
|
|
|
|
if (err) {
|
2013-10-22 08:37:32 -04:00
|
|
|
$scope.buttonEnabled = true;
|
2013-10-21 07:10:42 -04:00
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// login to imap backend
|
|
|
|
appController._emailDao.imapLogin(function(err) {
|
|
|
|
if (err) {
|
2013-10-22 08:37:32 -04:00
|
|
|
$scope.buttonEnabled = true;
|
2013-10-21 07:10:42 -04:00
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onLogin();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onLogin() {
|
|
|
|
$location.path('/desktop');
|
|
|
|
$scope.$apply();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return LoginExistingCtrl;
|
2013-10-22 08:37:32 -04:00
|
|
|
});
|