2020-11-10 14:37:44 +00:00
|
|
|
import { toastr } from "asc-web-common";
|
2020-11-12 08:50:21 +00:00
|
|
|
import {
|
|
|
|
setEncryptionKeys as setKeys,
|
2020-11-12 16:03:54 +00:00
|
|
|
//getEncryptionAccess,
|
2020-11-12 08:50:21 +00:00
|
|
|
} from "../store/auth/actions";
|
2020-11-13 16:05:49 +00:00
|
|
|
import assign from "lodash/assign";
|
|
|
|
import isEmpty from "lodash/isEmpty";
|
|
|
|
|
|
|
|
//import { store } from "asc-web-common";
|
2020-11-12 16:03:54 +00:00
|
|
|
|
|
|
|
// const { isDesktopClient, isEncryptionSupport } = store.auth.selectors;
|
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
//const state = store.getState();
|
2020-11-10 14:37:44 +00:00
|
|
|
|
2020-11-05 11:13:06 +00:00
|
|
|
const domain = window.location.origin;
|
|
|
|
const provider = "AppServer";
|
2020-11-11 12:47:37 +00:00
|
|
|
const guid = "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}";
|
2020-11-12 16:03:54 +00:00
|
|
|
const desktop = window["AscDesktopEditor"] !== undefined;
|
2020-11-13 18:45:28 +00:00
|
|
|
// const encryption =
|
|
|
|
// (desktop &&
|
|
|
|
// typeof window.AscDesktopEditor.cloudCryptoCommand === "function") ||
|
|
|
|
// false;
|
2020-11-12 16:03:54 +00:00
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
const encryptionKeyPair = {
|
2020-11-13 18:45:28 +00:00
|
|
|
// privateKeyEnc: "1",
|
|
|
|
// publicKey: "2",
|
2020-11-13 16:05:49 +00:00
|
|
|
};
|
2020-11-10 14:37:44 +00:00
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
export function regDesktop(user, isEncryption) {
|
|
|
|
if (!desktop) return;
|
2020-11-13 18:45:28 +00:00
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
const data = {
|
|
|
|
displayName: user.displayName,
|
|
|
|
email: user.email,
|
|
|
|
domain,
|
|
|
|
provider,
|
|
|
|
userId: user.id,
|
2020-11-10 14:37:44 +00:00
|
|
|
};
|
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
if (isEncryption) {
|
|
|
|
assign(data, {
|
|
|
|
encryptionKeys: {
|
|
|
|
cryptoEngineId: guid,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!isEmpty(encryptionKeyPair)) {
|
|
|
|
assign(data, {
|
|
|
|
encryptionKeys: {
|
|
|
|
cryptoEngineId: guid,
|
|
|
|
privateKeyEnc: encryptionKeyPair.privateKeyEnc,
|
|
|
|
publicKey: encryptionKeyPair.publicKey,
|
|
|
|
},
|
|
|
|
});
|
2020-11-13 18:45:28 +00:00
|
|
|
}
|
|
|
|
//else assign(data, {});
|
2020-11-13 16:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
window.AscDesktopEditor.execCommand("portal:login", JSON.stringify(data));
|
|
|
|
|
2020-11-10 14:37:44 +00:00
|
|
|
window.onSystemMessage = (e) => {
|
2020-11-13 16:05:49 +00:00
|
|
|
console.log("onSystemMessage: ", e);
|
2020-11-10 14:37:44 +00:00
|
|
|
let message = e.opMessage;
|
|
|
|
switch (e.type) {
|
|
|
|
case "operation":
|
|
|
|
if (!message) {
|
|
|
|
switch (e.opType) {
|
|
|
|
case 0:
|
|
|
|
message = "Preparing file for encryption";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
message = "Encrypting file";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
message = "Loading...";
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 18:45:28 +00:00
|
|
|
toastr.info(message);
|
|
|
|
break;
|
2020-11-05 11:13:06 +00:00
|
|
|
default:
|
2020-11-10 14:37:44 +00:00
|
|
|
break;
|
2020-11-05 11:13:06 +00:00
|
|
|
}
|
|
|
|
};
|
2020-11-12 16:03:54 +00:00
|
|
|
|
2020-11-13 16:05:49 +00:00
|
|
|
if (isEncryption) {
|
|
|
|
window.cloudCryptoCommand = (type, params, callback) => {
|
|
|
|
console.log("cloudCryptoCommand", params);
|
|
|
|
switch (type) {
|
2020-11-13 18:45:28 +00:00
|
|
|
case "encryptionKeys": {
|
2020-11-13 16:05:49 +00:00
|
|
|
setEncryptionKeys(params);
|
|
|
|
break;
|
2020-11-13 18:45:28 +00:00
|
|
|
}
|
|
|
|
case "relogin": {
|
|
|
|
toastr.info("Encryption keys must be re-entered");
|
2020-11-13 16:05:49 +00:00
|
|
|
relogin();
|
|
|
|
break;
|
2020-11-13 18:45:28 +00:00
|
|
|
}
|
2020-11-13 16:05:49 +00:00
|
|
|
case "getsharingkeys":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2020-11-03 06:52:05 +00:00
|
|
|
}
|
2020-11-12 08:50:21 +00:00
|
|
|
}
|
2020-11-03 06:52:05 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
export function relogin() {
|
2020-11-13 18:45:28 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
const data = {
|
|
|
|
domain,
|
|
|
|
onsuccess: "reload",
|
|
|
|
};
|
2020-11-12 08:50:21 +00:00
|
|
|
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
|
|
|
|
}, 1000);
|
|
|
|
}
|
2020-11-05 11:13:06 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
export function setEncryptionKeys(encryptionKeys) {
|
2020-11-12 16:03:54 +00:00
|
|
|
console.log("encryptionKeys: ", encryptionKeys);
|
2020-11-13 18:45:28 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
if (!encryptionKeys.publicKey || !encryptionKeys.privateKeyEnc) {
|
2020-11-13 18:45:28 +00:00
|
|
|
toastr.info("Empty encryption keys");
|
|
|
|
return;
|
2020-11-03 06:52:05 +00:00
|
|
|
}
|
2020-11-12 08:50:21 +00:00
|
|
|
const data = {
|
|
|
|
publicKey: encryptionKeys.publicKey,
|
|
|
|
privateKeyEnc: encryptionKeys.privateKeyEnc,
|
|
|
|
};
|
|
|
|
return setKeys(data);
|
|
|
|
}
|
2020-11-03 06:52:05 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
export function checkPwd() {
|
|
|
|
const data = {
|
|
|
|
domain,
|
|
|
|
emailInput: "login",
|
|
|
|
pwdInput: "password",
|
|
|
|
};
|
2020-11-13 18:45:28 +00:00
|
|
|
window.AscDesktopEditor.execCommand("portal:checkpwd", JSON.stringify(data));
|
2020-11-12 08:50:21 +00:00
|
|
|
}
|
2020-11-03 06:52:05 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
export function logout() {
|
|
|
|
const data = {
|
|
|
|
domain,
|
|
|
|
};
|
2020-11-13 18:45:28 +00:00
|
|
|
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
|
2020-11-03 06:52:05 +00:00
|
|
|
}
|