diff --git a/src/js/controller/account.js b/src/js/controller/account.js index e6d6332..bfd25a6 100644 --- a/src/js/controller/account.js +++ b/src/js/controller/account.js @@ -2,6 +2,7 @@ define(function(require) { 'use strict'; var appController = require('js/app-controller'), + dl = require('js/util/download'), emailDao; // @@ -23,33 +24,9 @@ define(function(require) { } var id = keys.keyId.substring(8, keys.keyId.length); - download(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain'); + dl.createDownload(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain'); }); }; - - // - // helper functions - // - - function download(content, filename, contentType) { - contentType = contentType || 'application/octet-stream'; - chrome.fileSystem.chooseEntry({ - type: 'saveFile', - suggestedName: filename - }, function(file) { - if (!file) { - return; - } - file.createWriter(function(writer) { - writer.onerror = console.error; - writer.onwriteend = function() {}; - writer.write(new Blob([content], { - type: contentType - })); - }, console.error); - }); - } - }; return AccountCtrl; diff --git a/src/js/controller/login-initial.js b/src/js/controller/login-initial.js index df640cf..c1e6899 100644 --- a/src/js/controller/login-initial.js +++ b/src/js/controller/login-initial.js @@ -1,47 +1,85 @@ define(function(require) { 'use strict'; - var appController = require('js/app-controller'); + var appController = require('js/app-controller'), + dl = require('js/util/download'); var LoginInitialCtrl = function($scope, $location) { + var emailDao = appController._emailDao, + states; + + $scope.states = states = { + IDLE: 1, + PROCESSING: 2, + DONE: 4 + }; + $scope.state = states.IDLE; // initial state + + + // + // scope functions + // $scope.confirmPassphrase = function() { var passphrase = $scope.passphrase, - confirmation = $scope.confirmation, - emailDao = appController._emailDao; + confirmation = $scope.confirmation; if (!passphrase || passphrase !== confirmation) { return; } - unlockCrypto(imapLogin); + setState(states.PROCESSING); + setTimeout(function() { + emailDao.unlock({}, passphrase, function(err) { + if (err) { + console.error(err); + setState(states.IDLE, true); + return; + } - function unlockCrypto(callback) { - emailDao.unlock({}, passphrase, callback); - } + setState(states.DONE, true); + }); + }, 500); + }; - function imapLogin(err) { + $scope.exportKeypair = function() { + // export keys from keychain + emailDao._crypto.exportKeys(function(err, keys) { if (err) { console.error(err); return; } - // login to imap backend - appController._emailDao.imapLogin(function(err) { - if (err) { - console.error(err); - return; - } - onLogin(); - }); - } + var id = keys.keyId.substring(8, keys.keyId.length); + dl.createDownload(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain'); + $scope.exported = true; + }); + }; + + $scope.proceed = function() { + // login to imap backend + appController._emailDao.imapLogin(function(err) { + if (err) { + console.error(err); + return; + } + onLogin(); + }); }; function onLogin() { $location.path('/desktop'); $scope.$apply(); } + + function setState(state, async) { + $scope.state = state; + + if (async) { + $scope.$apply(); + } + } }; return LoginInitialCtrl; -}); +}); \ No newline at end of file diff --git a/src/js/util/download.js b/src/js/util/download.js new file mode 100644 index 0000000..f8ee752 --- /dev/null +++ b/src/js/util/download.js @@ -0,0 +1,26 @@ +define(function() { + 'use strict'; + + var dl = {}; + + dl.createDownload = function(content, filename, contentType) { + contentType = contentType || 'application/octet-stream'; + chrome.fileSystem.chooseEntry({ + type: 'saveFile', + suggestedName: filename + }, function(file) { + if (!file) { + return; + } + file.createWriter(function(writer) { + writer.onerror = console.error; + writer.onwriteend = function() {}; + writer.write(new Blob([content], { + type: contentType + })); + }, console.error); + }); + }; + + return dl; +}); \ No newline at end of file diff --git a/src/tpl/login-initial.html b/src/tpl/login-initial.html index 3e4b168..cd08eab 100644 --- a/src/tpl/login-initial.html +++ b/src/tpl/login-initial.html @@ -4,7 +4,7 @@ -
+

Set passphrase

If you forget your passphrase, there is no way to restore your data. So it might be a good idea to write it down and keep it in a safe place.

@@ -20,4 +20,18 @@
+
+

Generating keypair

+ +

A batch of highly trained monkeys has been dispatched to collect entropy for your personal keypair. Please stand by...

+
+ +
+

Keypair generated

+ +

A keypair has been generated for you. Please store this key pair in a safe location before you proceed.

+ + +
+
\ No newline at end of file