mirror of
https://github.com/moparisthebest/mail
synced 2024-12-23 15:58:49 -05:00
export key pair on initial login
This commit is contained in:
parent
a52ba5a684
commit
8add506135
@ -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;
|
||||
|
@ -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;
|
||||
});
|
||||
});
|
26
src/js/util/download.js
Normal file
26
src/js/util/download.js
Normal file
@ -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;
|
||||
});
|
@ -4,7 +4,7 @@
|
||||
<div class="logo"></div>
|
||||
</div><!--/logo-->
|
||||
|
||||
<div class="content">
|
||||
<div class="content" ng-show="state === states.IDLE">
|
||||
<h1>Set passphrase</h1>
|
||||
|
||||
<p>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.</p>
|
||||
@ -20,4 +20,18 @@
|
||||
</form>
|
||||
</div><!--/content-->
|
||||
|
||||
<div class="content" ng-show="state === states.PROCESSING">
|
||||
<h1>Generating keypair</h1>
|
||||
|
||||
<p>A batch of highly trained monkeys has been dispatched to collect entropy for your personal keypair. Please stand by...</p>
|
||||
</div><!--/content-->
|
||||
|
||||
<div class="content" ng-show="state === states.DONE">
|
||||
<h1>Keypair generated</h1>
|
||||
|
||||
<p>A keypair has been generated for you. Please store this key pair in a safe location before you proceed.</p>
|
||||
<button ng-click="exportKeypair()" class="btn" tabindex="4">Export keypair</button>
|
||||
<button ng-click="proceed()" ng-disabled="!exported" class="btn" tabindex="4">Proceed</button>
|
||||
</div><!--/content-->
|
||||
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user