2013-10-21 07:10:42 -04:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
2013-11-14 14:44:57 -05:00
|
|
|
var appController = require('js/app-controller'),
|
|
|
|
errorUtil = require('js/util/error');
|
2013-10-21 07:10:42 -04:00
|
|
|
|
|
|
|
var LoginExistingCtrl = function($scope, $location) {
|
2013-11-14 14:44:57 -05:00
|
|
|
// global state... inherited to all child scopes
|
|
|
|
$scope.$root.state = {};
|
|
|
|
// attach global error handler
|
|
|
|
errorUtil.attachHandler($scope);
|
|
|
|
|
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-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
emailDao.unlock({
|
|
|
|
keypair: keypair,
|
|
|
|
passphrase: $scope.passphrase
|
|
|
|
}, onUnlock);
|
2013-11-04 08:20:14 -05:00
|
|
|
});
|
|
|
|
}
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-11-04 08:20:14 -05:00
|
|
|
function onUnlock(err) {
|
|
|
|
if (err) {
|
2013-12-03 07:15:10 -05:00
|
|
|
$scope.incorrect = true;
|
|
|
|
$scope.buttonEnabled = true;
|
|
|
|
$scope.$apply();
|
2013-11-04 08:20:14 -05:00
|
|
|
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;
|
2013-11-14 14:44:57 -05:00
|
|
|
$scope.onError(err);
|
2013-10-22 08:59:36 -04:00
|
|
|
}
|
2013-10-21 07:10:42 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return LoginExistingCtrl;
|
2013-10-22 08:37:32 -04:00
|
|
|
});
|