2013-10-21 11:10:45 -04:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var appController = require('js/app-controller'),
|
2013-10-23 11:17:36 -04:00
|
|
|
dl = require('js/util/download'),
|
2014-07-10 14:01:11 -04:00
|
|
|
config = require('js/app-config').config,
|
2014-04-11 12:39:13 -04:00
|
|
|
pgp, keychain, userId;
|
2013-10-21 11:10:45 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Controller
|
|
|
|
//
|
|
|
|
|
|
|
|
var AccountCtrl = function($scope) {
|
2014-04-11 12:39:13 -04:00
|
|
|
userId = appController._emailDao._account.emailAddress;
|
|
|
|
keychain = appController._keychain;
|
2014-06-13 06:33:30 -04:00
|
|
|
pgp = appController._pgp;
|
2013-10-21 11:10:45 -04:00
|
|
|
|
2013-11-08 17:53:33 -05:00
|
|
|
$scope.state.account = {
|
|
|
|
toggle: function(to) {
|
2014-04-23 09:24:48 -04:00
|
|
|
$scope.state.lightbox = (to) ? 'account' : undefined;
|
2013-11-08 17:53:33 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-06 10:20:49 -05:00
|
|
|
//
|
|
|
|
// scope variables
|
|
|
|
//
|
2013-11-06 11:19:39 -05:00
|
|
|
|
2014-04-11 12:39:13 -04:00
|
|
|
var keyParams = pgp.getKeyParams();
|
|
|
|
|
|
|
|
$scope.eMail = userId;
|
|
|
|
$scope.keyId = keyParams._id.slice(8);
|
|
|
|
var fpr = keyParams.fingerprint;
|
2013-11-06 11:19:39 -05:00
|
|
|
$scope.fingerprint = fpr.slice(0, 4) + ' ' + fpr.slice(4, 8) + ' ' + fpr.slice(8, 12) + ' ' + fpr.slice(12, 16) + ' ' + fpr.slice(16, 20) + ' ' + fpr.slice(20, 24) + ' ' + fpr.slice(24, 28) + ' ' + fpr.slice(28, 32) + ' ' + fpr.slice(32, 36) + ' ' + fpr.slice(36);
|
2014-04-11 12:39:13 -04:00
|
|
|
$scope.keysize = keyParams.bitSize;
|
2014-07-10 14:01:11 -04:00
|
|
|
$scope.publicKeyUrl = config.cloudUrl + '/' + userId;
|
2013-11-06 10:20:49 -05:00
|
|
|
|
2013-10-21 11:10:45 -04:00
|
|
|
//
|
|
|
|
// scope functions
|
|
|
|
//
|
|
|
|
|
|
|
|
$scope.exportKeyFile = function() {
|
2014-04-11 12:39:13 -04:00
|
|
|
keychain.getUserKeyPair(userId, function(err, keys) {
|
2013-10-21 11:10:45 -04:00
|
|
|
if (err) {
|
2013-11-11 11:56:51 -05:00
|
|
|
$scope.onError(err);
|
2013-10-21 11:10:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:39:13 -04:00
|
|
|
var keyId = keys.publicKey._id;
|
|
|
|
var file = 'whiteout_mail_' + userId + '_' + keyId.substring(8, keyId.length);
|
|
|
|
|
2013-11-04 15:07:32 -05:00
|
|
|
dl.createDownload({
|
2014-04-11 12:39:13 -04:00
|
|
|
content: keys.publicKey.publicKey + keys.privateKey.encryptedKey,
|
|
|
|
filename: file + '.asc',
|
2013-11-04 15:07:32 -05:00
|
|
|
contentType: 'text/plain'
|
2014-04-11 12:39:13 -04:00
|
|
|
}, onExport);
|
2013-10-21 11:10:45 -04:00
|
|
|
});
|
|
|
|
};
|
2014-04-11 12:39:13 -04:00
|
|
|
|
|
|
|
function onExport(err) {
|
|
|
|
if (err) {
|
|
|
|
$scope.onError(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.state.account.toggle(false);
|
|
|
|
$scope.$apply();
|
|
|
|
$scope.onError({
|
|
|
|
title: 'Success',
|
|
|
|
message: 'Exported keypair to file.'
|
|
|
|
});
|
|
|
|
}
|
2013-10-21 11:10:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return AccountCtrl;
|
|
|
|
});
|