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-11-04 08:20:14 -05:00
|
|
|
var emailDao = appController._emailDao;
|
|
|
|
|
2013-10-22 08:37:32 -04:00
|
|
|
$scope.buttonEnabled = true;
|
2013-10-22 08:59:36 -04:00
|
|
|
$scope.incorrect = false;
|
2013-10-22 08:37:32 -04:00
|
|
|
|
2013-11-04 09:56:27 -05:00
|
|
|
$scope.change = function() {
|
|
|
|
$scope.incorrect = false;
|
|
|
|
};
|
|
|
|
|
2013-10-21 07:10:42 -04:00
|
|
|
$scope.confirmPassphrase = function() {
|
2013-11-04 08:20:14 -05:00
|
|
|
if (!$scope.passphrase) {
|
2013-10-21 07:10:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-22 08:37:32 -04:00
|
|
|
// disable button once loggin has started
|
|
|
|
$scope.buttonEnabled = false;
|
2013-10-22 08:59:36 -04:00
|
|
|
$scope.incorrect = false;
|
2013-11-04 08:20:14 -05:00
|
|
|
unlockCrypto();
|
|
|
|
};
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-11-04 08:20:14 -05:00
|
|
|
function unlockCrypto() {
|
|
|
|
var userId = emailDao._account.emailAddress;
|
|
|
|
appController._emailDao._keychain.getUserKeyPair(userId, function(err, keypair) {
|
2013-10-21 07:10:42 -04:00
|
|
|
if (err) {
|
2013-10-22 08:59:36 -04:00
|
|
|
handleError(err);
|
2013-10-21 07:10:42 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-11-04 08:20:14 -05:00
|
|
|
emailDao.unlock(keypair, $scope.passphrase, onUnlock);
|
|
|
|
});
|
|
|
|
}
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-11-04 08:20:14 -05:00
|
|
|
function onUnlock(err) {
|
|
|
|
if (err) {
|
|
|
|
handleError(err);
|
|
|
|
return;
|
2013-10-21 07:10:42 -04:00
|
|
|
}
|
2013-11-04 08:20:14 -05:00
|
|
|
|
|
|
|
$location.path('/desktop');
|
|
|
|
$scope.$apply();
|
|
|
|
}
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-10-22 08:59:36 -04:00
|
|
|
function handleError(err) {
|
|
|
|
$scope.incorrect = true;
|
|
|
|
$scope.buttonEnabled = true;
|
|
|
|
$scope.$apply();
|
|
|
|
console.error(err);
|
|
|
|
}
|
2013-10-21 07:10:42 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return LoginExistingCtrl;
|
2013-10-22 08:37:32 -04:00
|
|
|
});
|