mail/src/js/controller/account.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

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'),
2013-10-21 11:10:45 -04:00
emailDao;
//
// Controller
//
var AccountCtrl = function($scope) {
emailDao = appController._emailDao;
2013-11-08 17:53:33 -05:00
$scope.state.account = {
open: false,
toggle: function(to) {
this.open = to;
}
};
2013-11-06 10:20:49 -05:00
//
// scope variables
//
2013-11-06 11:19:39 -05:00
2013-11-06 10:20:49 -05:00
var fpr = emailDao._crypto.getFingerprint(),
keyId = emailDao._crypto.getKeyId();
$scope.eMail = emailDao._account.emailAddress;
2013-11-06 11:19:39 -05:00
$scope.keyId = keyId.slice(8);
$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);
2013-11-06 10:20:49 -05:00
$scope.keysize = emailDao._account.asymKeySize;
2013-10-21 11:10:45 -04:00
//
// scope functions
//
$scope.exportKeyFile = function() {
emailDao._crypto.exportKeys(function(err, keys) {
2013-10-21 11:10:45 -04:00
if (err) {
$scope.onError(err);
2013-10-21 11:10:45 -04:00
return;
}
2013-10-22 10:45:50 -04:00
var id = keys.keyId.substring(8, keys.keyId.length);
dl.createDownload({
content: keys.publicKeyArmored + keys.privateKeyArmored,
filename: id + '.asc',
contentType: 'text/plain'
}, function onSave(err) {
if (err) {
$scope.onError(err);
return;
}
});
2013-10-21 11:10:45 -04:00
});
};
};
return AccountCtrl;
});