use the same APIs when creating invites as you do when redeeming them

pull/1/head
ansuz 5 years ago
parent 042cfffbe8
commit af463c2de9

@ -14,14 +14,14 @@ define([
'/customize/application_config.js', '/customize/application_config.js',
'/customize/pages.js', '/customize/pages.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/common/invitation.js',
'/bower_components/scrypt-async/scrypt-async.js', '/bower_components/scrypt-async/scrypt-async.js',
'css!/customize/fonts/cptools/style.css', 'css!/customize/fonts/cptools/style.css',
'/bower_components/croppie/croppie.min.js', '/bower_components/croppie/croppie.min.js',
'css!/bower_components/croppie/croppie.css', 'css!/bower_components/croppie/croppie.css',
], function ($, Config, Util, Hash, Language, UI, Constants, Feedback, h, MediaTag, Clipboard, ], function ($, Config, Util, Hash, Language, UI, Constants, Feedback, h, MediaTag, Clipboard,
Messages, AppConfig, Pages, NThen) { Messages, AppConfig, Pages, NThen, InviteInner) {
var Scrypt = window.scrypt;
var UIElements = {}; var UIElements = {};
// Configure MediaTags to use our local viewer // Configure MediaTags to use our local viewer
@ -1681,6 +1681,10 @@ define([
$(linkError).text('empty name...').show(); // XXX $(linkError).text('empty name...').show(); // XXX
return true; return true;
} }
var seeds = InviteInner.deriveSeeds(hashData.key);
var salt = InviteInner.deriveSalt(pw, AppConfig.loginSalt);
var bytes64; var bytes64;
NThen(function (waitFor) { NThen(function (waitFor) {
$(linkForm).hide(); $(linkForm).hide();
@ -1688,17 +1692,9 @@ define([
$nav.find('button.cp-teams-invite-create').prop('disabled', 'disabled'); $nav.find('button.cp-teams-invite-create').prop('disabled', 'disabled');
setTimeout(waitFor(), 150); setTimeout(waitFor(), 150);
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Scrypt InviteInner.deriveBytes(seeds.scrypt, salt, waitFor(function (_bytes) {
Scrypt(hashData.key, bytes64 = _bytes;
(pw || '') + (AppConfig.loginSalt || ''), // salt }));
8, // memoryCost (n)
1024, // block size parameter (r)
192, // dkLen
200, // interruptStep
waitFor(function (_bytes) {
bytes64 = _bytes;
}),
'base64'); // format, could be 'base64'
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
$(linkSpinText).text('Add invite link to team'); // XXX $(linkSpinText).text('Add invite link to team'); // XXX
module.execCommand('CREATE_INVITE_LINK', { module.execCommand('CREATE_INVITE_LINK', {
@ -1708,6 +1704,7 @@ define([
bytes64: bytes64, bytes64: bytes64,
hash: hash, hash: hash,
teamId: config.teamId, teamId: config.teamId,
seeds: seeds,
}, waitFor(function (obj) { }, waitFor(function (obj) {
if (obj && obj.error) { if (obj && obj.error) {
waitFor.abort(); waitFor.abort();

@ -42,6 +42,18 @@ var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) {
cb, cb,
'base64'); // format, could be 'base64' 'base64'); // format, could be 'base64'
}; };
Invite.getPreviewContent = function (seeds, cb) {
var secrets = Invite.derivePreviewSecrets(seeds);
secrets = secrets;
cb("NOT_IMPLEMENTED"); // XXX cryptget
};
// XXX remember to pin invites...
Invite.setPreviewContent = function (seeds, cb) {
cb = cb;
};
return Invite; return Invite;
}; };
if (typeof(module) !== 'undefined' && module.exports) { if (typeof(module) !== 'undefined' && module.exports) {

@ -1053,26 +1053,45 @@ define([
var $div = $(div); var $div = $(div);
$div.empty(); $div.empty();
var bytes64; var bytes64;
nThen(function (waitFor) { nThen(function (waitFor) {
$div.append(h('div', [ // XXX show something while we're waiting for the invite preview content
h('i.fa.fa-spin.fa-spinner'), waitFor = waitFor;
h('span', 'Scrypt...') // XXX
]));
setTimeout(waitFor(), 150);
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
var salt = InviteInner.deriveSalt(pw, AppConfig.loginSalt); InviteInner.getPreviewContent(seeds, waitFor(function (err, json) {
InviteInner.deriveBytes(seeds.scrypt, salt, waitFor(function (bytes) { json = json; // XXX {message: "", author: "", ???}
bytes64 = bytes; if (err) {
})); // XXX handle errors
}).nThen(function (waitFor) { }
APP.module.execCommand('GET_LINK_DATA', { // XXX show invite preview content
bytes64: bytes64,
hash: hash, var button = h('button', 'XXX');
password: pw, button.onclick = function () {
}, waitFor(function () { nThen(function (waitFor) {
$div.empty(); $div.append(h('div', [
// TODO h('i.fa.fa-spin.fa-spinner'),
// Accept/decline/decide later UI h('span', 'Scrypt...') // XXX
]));
setTimeout(waitFor(), 150);
}).nThen(function (waitFor) {
var salt = InviteInner.deriveSalt(pw, AppConfig.loginSalt);
InviteInner.deriveBytes(seeds.scrypt, salt, waitFor(function (bytes) {
bytes64 = bytes;
}));
}).nThen(function (waitFor) {
APP.module.execCommand('GET_LINK_DATA', {
bytes64: bytes64,
hash: hash,
password: pw,
}, waitFor(function () {
$div.empty();
// TODO
// Accept/decline/decide later UI
}));
});
};
$div.append(button);
})); }));
}); });
}; };

Loading…
Cancel
Save