1
0
mirror of https://github.com/moparisthebest/mail synced 2024-08-13 16:43:47 -04:00
mail/src/js/controller/login-existing.js

65 lines
1.8 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-22 08:59:36 -04:00
$scope.incorrect = false;
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-22 08:59:36 -04:00
$scope.incorrect = 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) {
2013-10-22 08:59:36 -04:00
handleError(err);
2013-10-21 07:10:42 -04:00
return;
}
// login to imap backend
appController._emailDao.imapLogin(function(err) {
if (err) {
2013-10-22 08:59:36 -04:00
handleError(err);
2013-10-21 07:10:42 -04:00
return;
}
onLogin();
});
}
};
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
function onLogin() {
$location.path('/desktop');
$scope.$apply();
}
};
return LoginExistingCtrl;
});