2014-10-02 16:05:44 -04:00
|
|
|
'use strict';
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-11-19 14:54:59 -05: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() {
|
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-11-12 10:12:26 -05:00
|
|
|
$scope.busy = true;
|
|
|
|
$scope.errMsg = undefined;
|
2014-10-02 16:05:44 -04:00
|
|
|
$scope.incorrect = false;
|
2014-11-12 10:12:26 -05:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
unlockCrypto();
|
|
|
|
};
|
2013-11-04 09:56:27 -05:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
function unlockCrypto() {
|
2014-11-19 14:54:59 -05:00
|
|
|
var userId = auth.emailAddress;
|
|
|
|
keychain.getUserKeyPair(userId, function(err, keypair) {
|
2014-10-02 16:05:44 -04:00
|
|
|
if (err) {
|
2014-11-12 10:12:26 -05:00
|
|
|
displayError(err);
|
2013-10-21 07:10:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-19 14:54:59 -05:00
|
|
|
email.unlock({
|
2014-10-02 16:05:44 -04:00
|
|
|
keypair: keypair,
|
|
|
|
passphrase: $scope.passphrase
|
|
|
|
}, onUnlock);
|
|
|
|
});
|
|
|
|
}
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-10-02 16:05:44 -04:00
|
|
|
function onUnlock(err) {
|
|
|
|
if (err) {
|
2014-11-12 10:12:26 -05:00
|
|
|
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
|
|
|
|
2014-11-19 14:54:59 -05:00
|
|
|
auth.storeCredentials(function(err) {
|
2013-11-04 08:20:14 -05:00
|
|
|
if (err) {
|
2014-11-12 10:12:26 -05:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
$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;
|