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

48 lines
1.3 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, $q, 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;
}
return $q(function(resolve) {
$scope.busy = true;
$scope.errMsg = undefined;
$scope.incorrect = false;
resolve();
}).then(function() {
// key keypair
var userId = auth.emailAddress;
return keychain.getUserKeyPair(userId);
2013-10-21 07:10:42 -04:00
}).then(function(keypair) {
// unlock email service
return email.unlock({
2014-10-02 16:05:44 -04:00
keypair: keypair,
passphrase: $scope.passphrase
});
}).then(function() {
// persist credentials locally
return auth.storeCredentials();
2013-11-04 08:20:14 -05:00
}).then(function() {
// go to main account screen
2014-12-02 10:12:42 -05:00
$location.path('/account');
}).catch(displayError);
};
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;
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;