1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-12 04:05:13 -05:00
mail/src/js/controller/login-existing.js

57 lines
1.5 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');
var LoginExistingCtrl = function($scope, $location) {
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.$apply();
console.error(err);
}
2013-10-21 07:10:42 -04:00
};
return LoginExistingCtrl;
});