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

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
2013-10-21 07:10:42 -04:00
var LoginExistingCtrl = function($scope, $location, $routeParams, email, auth, keychain) {
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
2013-11-04 08:20:14 -05:00
2014-10-02 16:05:44 -04:00
$scope.confirmPassphrase = function() {
if ($scope.form.$invalid) {
$scope.errMsg = 'Please fill out all required fields!';
2014-10-02 16:05:44 -04:00
return;
}
$scope.busy = true;
$scope.errMsg = undefined;
2014-10-02 16:05:44 -04:00
$scope.incorrect = false;
2014-10-02 16:05:44 -04:00
unlockCrypto();
};
2014-10-02 16:05:44 -04:00
function unlockCrypto() {
var userId = auth.emailAddress;
keychain.getUserKeyPair(userId, function(err, keypair) {
2014-10-02 16:05:44 -04:00
if (err) {
displayError(err);
2013-10-21 07:10:42 -04:00
return;
}
email.unlock({
2014-10-02 16:05:44 -04:00
keypair: keypair,
passphrase: $scope.passphrase
}, onUnlock);
});
}
2014-10-02 16:05:44 -04:00
function onUnlock(err) {
if (err) {
displayError(err);
2014-10-02 16:05:44 -04:00
return;
2013-11-04 08:20:14 -05:00
}
2013-10-21 07:10:42 -04:00
auth.storeCredentials(function(err) {
2013-11-04 08:20:14 -05:00
if (err) {
displayError(err);
return;
2013-10-21 07:10:42 -04:00
}
2013-11-04 08:20:14 -05:00
2014-12-02 10:12:42 -05:00
$location.path('/account');
2014-10-02 16:05:44 -04:00
$scope.$apply();
});
}
2013-10-21 07:10:42 -04:00
function displayError(err) {
$scope.busy = false;
2014-10-02 16:05:44 -04:00
$scope.incorrect = true;
$scope.errMsg = err.errMsg || err.message;
$scope.$apply();
2014-10-02 16:05:44 -04:00
}
};
2013-10-21 07:10:42 -04:00
2014-10-08 06:34:34 -04:00
module.exports = LoginExistingCtrl;