Review imap key-sync

This commit is contained in:
Tankred Hase 2015-04-01 14:24:46 +02:00
parent f41e6e12b9
commit c8f13511c1
8 changed files with 27 additions and 19 deletions

View File

@ -204,9 +204,12 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o
showNegativeBtn: true, showNegativeBtn: true,
callback: function(granted) { callback: function(granted) {
if (granted) { if (granted) {
// send to key upload screen // logout of the current session
$timeout(function() { email.onDisconnect().then(function() {
$location.path('/login-privatekey-upload'); // send to key upload screen
$timeout(function() {
$location.path('/login-privatekey-upload');
});
}); });
} }
} }

View File

@ -54,9 +54,10 @@ var LoginPrivateKeyDownloadCtrl = function($scope, $location, $routeParams, $q,
return email.unlock({ return email.unlock({
keypair: cachedKeypair, keypair: cachedKeypair,
passphrase: undefined passphrase: undefined
}).catch(function() { }).catch(function(err) {
// passphrase incorrct ... go to passphrase login screen // passphrase incorrct ... go to passphrase login screen
$scope.goTo('/login-existing'); $scope.goTo('/login-existing');
throw err;
}); });
}).then(function() { }).then(function() {

View File

@ -22,18 +22,17 @@ var LoginPrivateKeyUploadCtrl = function($scope, $location, $routeParams, $q, au
// //
$scope.encryptAndUploadKey = function() { $scope.encryptAndUploadKey = function() {
if ($scope.inputCode.toUpperCase() !== $scope.code) {
$scope.errMsg = 'The code does not match. Please go back and check the generated code.';
return;
}
// register device to keychain service
return $q(function(resolve) { return $q(function(resolve) {
$scope.busy = true; $scope.busy = true;
$scope.errMsg = undefined; $scope.errMsg = undefined;
$scope.incorrect = false; $scope.incorrect = false;
resolve(); resolve();
}).then(function() {
if ($scope.inputCode.toUpperCase() !== $scope.code) {
throw new Error('The code does not match. Please go back and check the generated code.');
}
}).then(function() { }).then(function() {
// login to imap // login to imap
return privateKey.init(); return privateKey.init();

View File

@ -41,7 +41,7 @@ PrivateKey.prototype.init = function() {
* Cleanup by logging out of the imap client. * Cleanup by logging out of the imap client.
*/ */
PrivateKey.prototype.destroy = function() { PrivateKey.prototype.destroy = function() {
this._imap.login(); this._imap.logout();
// don't wait for logout to complete // don't wait for logout to complete
return new Promise(function(resolve) { return new Promise(function(resolve) {
resolve(); resolve();
@ -111,8 +111,10 @@ PrivateKey.prototype.upload = function(options) {
path: IMAP_KEYS_FOLDER path: IMAP_KEYS_FOLDER
}).then(function() { }).then(function() {
self._axe.debug('Successfully created imap folder ' + IMAP_KEYS_FOLDER); self._axe.debug('Successfully created imap folder ' + IMAP_KEYS_FOLDER);
}).catch(function() { }).catch(function(err) {
self._axe.debug('Creating imap folder ' + IMAP_KEYS_FOLDER + ' failed. Probably already available.'); var prettyErr = new Error('Creating imap folder ' + IMAP_KEYS_FOLDER + ' failed: ' + err.message);
self._axe.error(prettyErr);
throw prettyErr;
}); });
}).then(createMessage).then(function(message) { }).then(createMessage).then(function(message) {
// upload to imap folder // upload to imap folder

View File

@ -31,8 +31,11 @@
<div ng-show="step === 2"> <div ng-show="step === 2">
<p class="typo-paragraph">Please confirm the backup code you have written down.</p> <p class="typo-paragraph">Please confirm the backup code you have written down.</p>
<form class="form"> <form class="form">
<p class="form__error-message" ng-show="errMsg">{{errMsg}}</p>
<div class="form__row"> <div class="form__row">
<input type="text" class="input-text" ng-model="inputCode" wo-input-code wo-focus-me="step === 2" <input type="text" class="input-text" ng-class="{'input-text--error':incorrect}"
ng-model="inputCode" wo-input-code wo-focus-me="step === 2"
required pattern="([a-zA-Z0-9\-]*)" placeholder="0000-0000-0000-0000-0000-0000" required pattern="([a-zA-Z0-9\-]*)" placeholder="0000-0000-0000-0000-0000-0000"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"> autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div> </div>

View File

@ -103,12 +103,11 @@ describe('Login Private Key Download Controller unit test', function() {
keyId: cachedKeypair.publicKey._id keyId: cachedKeypair.publicKey._id
}).returns(resolves(encryptedPrivateKey)); }).returns(resolves(encryptedPrivateKey));
privateKeyStub.decrypt.returns(resolves(privkey)); privateKeyStub.decrypt.returns(resolves(privkey));
emailDaoMock.unlock.returns(rejects()); emailDaoMock.unlock.returns(rejects(new Error()));
authMock.storeCredentials.returns(resolves()); authMock.storeCredentials.returns(resolves());
privateKeyStub.destroy.returns(resolves()); privateKeyStub.destroy.returns(resolves());
scope.checkCode().then(function() { scope.checkCode().then(function() {
expect(scope.errMsg).to.not.exist;
expect(scope.goTo.withArgs('/login-existing').calledOnce).to.be.true; expect(scope.goTo.withArgs('/login-existing').calledOnce).to.be.true;
done(); done();
}); });

View File

@ -57,8 +57,9 @@ describe('Login Private Key Upload Controller unit test', function() {
it('should fail for invalid code', function() { it('should fail for invalid code', function() {
scope.inputCode = 'asdf'; scope.inputCode = 'asdf';
scope.encryptAndUploadKey(); scope.encryptAndUploadKey().then(function() {
expect(scope.errMsg).to.match(/go back and check/); expect(scope.errMsg).to.match(/go back and check/);
});
}); });
it('should work', function(done) { it('should work', function(done) {

View File

@ -35,7 +35,7 @@ describe('Private Key DAO unit tests', function() {
describe('destroy', function() { describe('destroy', function() {
it('should work', function(done) { it('should work', function(done) {
privkeyDao.destroy().then(function() { privkeyDao.destroy().then(function() {
expect(imapClientStub.login.calledOnce).to.be.true; expect(imapClientStub.logout.calledOnce).to.be.true;
done(); done();
}); });
}); });