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

58 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');
var LoginExistingCtrl = function($scope, $location) {
$scope.buttonEnabled = true;
2013-10-21 07:10:42 -04:00
$scope.confirmPassphrase = function() {
var passphrase = $scope.passphrase,
emailDao = appController._emailDao;
if (!passphrase) {
return;
}
// disable button once loggin has started
$scope.buttonEnabled = false;
2013-10-21 07:10:42 -04:00
unlockCrypto(imapLogin);
function unlockCrypto(callback) {
var userId = emailDao._account.emailAddress;
emailDao._keychain.getUserKeyPair(userId, function(err, keypair) {
if (err) {
callback(err);
return;
}
emailDao.unlock(keypair, passphrase, callback);
});
}
function imapLogin(err) {
if (err) {
$scope.buttonEnabled = true;
2013-10-21 07:10:42 -04:00
console.error(err);
return;
}
// login to imap backend
appController._emailDao.imapLogin(function(err) {
if (err) {
$scope.buttonEnabled = true;
2013-10-21 07:10:42 -04:00
console.error(err);
return;
}
onLogin();
});
}
};
function onLogin() {
$location.path('/desktop');
$scope.$apply();
}
};
return LoginExistingCtrl;
});