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

85 lines
2.1 KiB
JavaScript
Raw Normal View History

2013-10-21 07:10:42 -04:00
define(function(require) {
'use strict';
var appController = require('js/app-controller'),
errorUtil = require('js/util/error');
2013-10-21 07:10:42 -04:00
var LoginExistingCtrl = function($scope, $location) {
// 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;
$scope.buttonEnabled = true;
2013-10-22 08:59:36 -04:00
$scope.incorrect = false;
//
// Try unlocking without passphrase
//
unlockCrypto(function(err) {
if (err) {
return;
}
$location.path('/desktop');
$scope.$apply();
});
//
// Unlock using passphrase
//
$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;
}
// disable button once loggin has started
$scope.buttonEnabled = false;
2013-10-22 08:59:36 -04:00
$scope.incorrect = false;
unlockCrypto(onUnlock);
2013-11-04 08:20:14 -05:00
};
2013-10-21 07:10:42 -04:00
function unlockCrypto(callback) {
2013-11-04 08:20:14 -05:00
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;
}
emailDao.unlock({
keypair: keypair,
passphrase: $scope.passphrase
}, callback);
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) {
$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;
$scope.onError(err);
2013-10-22 08:59:36 -04:00
}
2013-10-21 07:10:42 -04:00
};
return LoginExistingCtrl;
});