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

62 lines
1.6 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;
$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;
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.onError(err);
2013-10-22 08:59:36 -04:00
}
2013-10-21 07:10:42 -04:00
};
return LoginExistingCtrl;
});