mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Moved FORM_FETCH_ANSWERS to sframe-common-outer.js
This commit is contained in:
parent
0a0b018df0
commit
af9d7646f7
@ -239,10 +239,23 @@ define([
|
||||
transform(ctx, parsed.type, val, function (res) {
|
||||
if (ctx.stop) { return; }
|
||||
if (!res.data) { return void error('EEMPTY'); }
|
||||
ctx.sframeChan.query("Q_FORM_FETCH_ANSWERS", JSON.parse(val)["answers"], function (err, obj) {
|
||||
var answers = obj && obj.results;
|
||||
console.log("ANSWERS", answers)
|
||||
});
|
||||
var data = JSON.parse(val)
|
||||
var _answers = data["answers"]
|
||||
if (data.form) {
|
||||
_answers['href'] = parsed.hash
|
||||
_answers['password'] = fData.password
|
||||
_answers['drive'] = true
|
||||
var answers
|
||||
ctx.sframeChan.query("Q_FORM_FETCH_ANSWERS", _answers, function (err, obj) {
|
||||
answers = obj && obj.results;
|
||||
console.log("ANSWERS", answers)
|
||||
});
|
||||
// var opts = {
|
||||
// binary: true,
|
||||
// };
|
||||
// zip.file(fileName, answers, opts);
|
||||
}
|
||||
|
||||
var fileName = getUnique(sanitize(rawName), res.ext, existingNames);
|
||||
existingNames.push(fileName.toLowerCase());
|
||||
zip.file(fileName, res.data, opts);
|
||||
|
||||
@ -2433,6 +2433,7 @@ define([
|
||||
});
|
||||
|
||||
sframeChan.on('Q_FORM_FETCH_ANSWERS', function (data, _cb) {
|
||||
var formHref = data.href
|
||||
var cb = Utils.Util.once(_cb);
|
||||
var myKeys = {};
|
||||
var myFormKeys;
|
||||
@ -2489,14 +2490,18 @@ define([
|
||||
if (myFormKeys.formSeed) {
|
||||
myFormKeys = getAnonymousKeys(myFormKeys.formSeed, data.channel);
|
||||
}
|
||||
|
||||
var keys = Utils.secret && Utils.secret.keys;
|
||||
|
||||
var formData = Utils.Hash.getFormData(Utils.secret);
|
||||
console.log("SECRET", Utils.secret)
|
||||
console.log("FORMDATA", formData)
|
||||
privateKey = formData.form_private;
|
||||
publicKey = formData.form_public;
|
||||
var keys;
|
||||
var privateKey, publicKey;
|
||||
if (data.drive) {
|
||||
var secret = Utils.Hash.getSecrets('form', formHref, data.password);
|
||||
keys = secret && secret.keys;
|
||||
var formData = Utils.Hash.getFormData(secret);
|
||||
privateKey = formData.form_private;
|
||||
publicKey = formData.form_public;
|
||||
|
||||
} else {
|
||||
keys = Utils.secret && Utils.secret.keys;
|
||||
}
|
||||
|
||||
var curvePrivate = privateKey || data.privateKey;
|
||||
if (!curvePrivate) { return void cb({error: 'EFORBIDDEN'}); }
|
||||
@ -2506,10 +2511,6 @@ define([
|
||||
validateKey: data.validateKey
|
||||
});
|
||||
|
||||
console.log("PRIVATE", curvePrivate)
|
||||
console.log("PUBLIC", publicKey, data.publicKey)
|
||||
console.log("VALIDATE", data.validateKey)
|
||||
|
||||
var config = {
|
||||
network: network,
|
||||
channel: data.channel,
|
||||
@ -2563,6 +2564,28 @@ define([
|
||||
// If we have a "non-anonymous" answer, it may be the edition of a
|
||||
// previous anonymous answer. Check if a previous anonymous answer exists
|
||||
// with the same uid and delete it.
|
||||
var u8_slice = function (A, start, end) {
|
||||
return new Uint8Array(Array.prototype.slice.call(A, start, end));
|
||||
};
|
||||
var checkAnonProof = function (proofObj, channel, curvePrivate) {
|
||||
var pub = proofObj.key;
|
||||
var proofTxt = proofObj.proof;
|
||||
try {
|
||||
var u8_bundle = Nacl.util.decodeBase64(proofTxt);
|
||||
var u8_nonce = u8_slice(u8_bundle, 0, Nacl.box.nonceLength);
|
||||
var u8_cipher = u8_slice(u8_bundle, Nacl.box.nonceLength);
|
||||
var u8_plain = Nacl.box.open(
|
||||
u8_cipher,
|
||||
u8_nonce,
|
||||
Nacl.util.decodeBase64(pub),
|
||||
Nacl.util.decodeBase64(curvePrivate)
|
||||
);
|
||||
return channel === Nacl.util.encodeUTF8(u8_plain);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (parsed._proof) {
|
||||
var check = checkAnonProof(parsed._proof, data.channel, curvePrivate);
|
||||
var theirAnonKey = parsed._proof.key;
|
||||
|
||||
@ -50,6 +50,7 @@ define([
|
||||
'css!/lib/datepicker/flatpickr.min.css',
|
||||
'css!/components/components-font-awesome/css/font-awesome.min.css',
|
||||
'less!/form/app-form.less',
|
||||
'/common/sframe-common-outer.js'
|
||||
], function (
|
||||
$,
|
||||
Sortify,
|
||||
@ -78,7 +79,8 @@ define([
|
||||
DatePicker,
|
||||
Share, Access, Properties,
|
||||
Flatpickr,
|
||||
Sortable
|
||||
Sortable,
|
||||
SFCommonO
|
||||
)
|
||||
{
|
||||
|
||||
@ -5375,6 +5377,7 @@ define([
|
||||
}
|
||||
|
||||
var getMyAnswers = APP.getMyAnswers = function () {
|
||||
var sframeChan = framework._.sfCommon.getSframeChannel();
|
||||
sframeChan.query("Q_FETCH_MY_ANSWERS", {
|
||||
channel: content.answers.channel,
|
||||
validateKey: content.answers.validateKey,
|
||||
|
||||
@ -129,6 +129,9 @@ define([
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var beep = function () {
|
||||
|
||||
}
|
||||
|
||||
var deleteLines = false; // "false" to support old forms
|
||||
sframeChan.on('Q_FORM_FETCH_ANSWERS', function (data, _cb) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user