2014-10-02 16:05:44 -04:00
|
|
|
'use strict';
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
var LoginExistingCtrl = function($scope, $location, $routeParams, $q, email, auth, keychain) {
|
2014-11-19 14:54:59 -05:00
|
|
|
!$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() {
|
2014-11-12 10:12:26 -05:00
|
|
|
if ($scope.form.$invalid) {
|
|
|
|
$scope.errMsg = 'Please fill out all required fields!';
|
2014-10-02 16:05:44 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-10-22 08:37:32 -04:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
return $q(function(resolve) {
|
|
|
|
$scope.busy = true;
|
|
|
|
$scope.errMsg = undefined;
|
|
|
|
$scope.incorrect = false;
|
|
|
|
resolve();
|
2014-11-12 10:12:26 -05:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
}).then(function() {
|
|
|
|
// key keypair
|
|
|
|
var userId = auth.emailAddress;
|
|
|
|
return keychain.getUserKeyPair(userId);
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
}).then(function(keypair) {
|
|
|
|
// unlock email service
|
|
|
|
return email.unlock({
|
2014-10-02 16:05:44 -04:00
|
|
|
keypair: keypair,
|
|
|
|
passphrase: $scope.passphrase
|
2014-12-16 10:14:16 -05:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
}).then(function() {
|
|
|
|
// persist credentials locally
|
|
|
|
return auth.storeCredentials();
|
2013-11-04 08:20:14 -05:00
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
}).then(function() {
|
|
|
|
// go to main account screen
|
2014-12-02 10:12:42 -05:00
|
|
|
$location.path('/account');
|
2014-12-16 10:14:16 -05:00
|
|
|
|
|
|
|
}).catch(displayError);
|
|
|
|
};
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-11-12 10:12:26 -05:00
|
|
|
function displayError(err) {
|
|
|
|
$scope.busy = false;
|
2014-10-02 16:05:44 -04:00
|
|
|
$scope.incorrect = true;
|
2014-11-12 10:12:26 -05:00
|
|
|
$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;
|