2020-11-13 16:05:49 +00:00
|
|
|
import isEmpty from "lodash/isEmpty";
|
2020-11-23 14:28:24 +00:00
|
|
|
import omit from "lodash/omit";
|
2023-12-29 11:37:04 +00:00
|
|
|
|
|
|
|
import { toastr } from "../components/toast";
|
2024-01-17 08:53:48 +00:00
|
|
|
import { TTranslation } from "../types";
|
|
|
|
import { TUser } from "../api/people/types";
|
|
|
|
import { ThemeKeys } from "../enums";
|
2023-12-29 11:37:04 +00:00
|
|
|
|
2024-01-25 13:13:51 +00:00
|
|
|
import { desktopConstants, getEditorTheme } from "./common";
|
2023-12-29 11:37:04 +00:00
|
|
|
import { checkIsSSR } from "./device";
|
2022-08-17 08:56:50 +00:00
|
|
|
|
|
|
|
const isSSR = checkIsSSR();
|
2020-12-04 09:59:48 +00:00
|
|
|
|
2020-12-28 07:40:50 +00:00
|
|
|
export function regDesktop(
|
2023-12-29 11:37:04 +00:00
|
|
|
user: TUser,
|
|
|
|
isEncryption: boolean,
|
|
|
|
keys: string[],
|
|
|
|
setEncryptionKeys: (value: string[]) => void,
|
|
|
|
isEditor: boolean,
|
|
|
|
getEncryptionAccess: (callback?: () => void) => void,
|
|
|
|
t: TTranslation,
|
2020-12-28 07:40:50 +00:00
|
|
|
) {
|
2022-08-17 08:56:50 +00:00
|
|
|
if (!isSSR) {
|
|
|
|
const data = {
|
|
|
|
displayName: user.displayName,
|
|
|
|
email: user.email,
|
|
|
|
domain: desktopConstants.domain,
|
|
|
|
provider: desktopConstants.provider,
|
|
|
|
userId: user.id,
|
2024-01-17 08:53:48 +00:00
|
|
|
uiTheme: getEditorTheme(user.theme || ThemeKeys.BaseStr),
|
2022-08-17 08:56:50 +00:00
|
|
|
};
|
2021-09-29 12:02:54 +00:00
|
|
|
|
2022-08-17 08:56:50 +00:00
|
|
|
let extendedData;
|
2020-11-13 16:05:49 +00:00
|
|
|
|
2022-08-17 08:56:50 +00:00
|
|
|
if (isEncryption) {
|
2020-11-16 14:42:29 +00:00
|
|
|
extendedData = {
|
2022-08-17 08:56:50 +00:00
|
|
|
...data,
|
|
|
|
encryptionKeys: {
|
|
|
|
cryptoEngineId: desktopConstants.cryptoEngineId,
|
|
|
|
},
|
2020-11-16 14:42:29 +00:00
|
|
|
};
|
2022-08-17 08:56:50 +00:00
|
|
|
|
|
|
|
if (!isEmpty(keys)) {
|
|
|
|
const filteredKeys = omit(keys, ["userId"]);
|
|
|
|
extendedData = {
|
|
|
|
...extendedData,
|
|
|
|
encryptionKeys: { ...extendedData.encryptionKeys, ...filteredKeys },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extendedData = { ...data };
|
2020-11-13 18:45:28 +00:00
|
|
|
}
|
2020-11-13 16:05:49 +00:00
|
|
|
|
2023-12-29 11:37:04 +00:00
|
|
|
window.AscDesktopEditor?.execCommand(
|
2022-08-17 08:56:50 +00:00
|
|
|
"portal:login",
|
2023-12-29 11:37:04 +00:00
|
|
|
JSON.stringify(extendedData),
|
2022-08-17 08:56:50 +00:00
|
|
|
);
|
2020-11-13 16:05:49 +00:00
|
|
|
|
2022-08-17 08:56:50 +00:00
|
|
|
if (isEncryption) {
|
|
|
|
window.cloudCryptoCommand = (type, params, callback) => {
|
|
|
|
switch (type) {
|
|
|
|
case "encryptionKeys": {
|
|
|
|
setEncryptionKeys(params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "updateEncryptionKeys": {
|
|
|
|
setEncryptionKeys(params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "relogin": {
|
2023-10-23 08:48:28 +00:00
|
|
|
// toastr.info(t("Common:EncryptionKeysReload"));
|
2023-12-29 11:37:04 +00:00
|
|
|
// relogin();
|
2022-08-17 08:56:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "getsharingkeys":
|
|
|
|
if (!isEditor || typeof getEncryptionAccess !== "function") {
|
|
|
|
callback({});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getEncryptionAccess(callback);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-11-19 15:30:29 +00:00
|
|
|
}
|
2022-08-17 08:56:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onSystemMessage = (e) => {
|
|
|
|
let message = e.opMessage;
|
|
|
|
switch (e.type) {
|
|
|
|
case "operation":
|
|
|
|
if (!message) {
|
|
|
|
switch (e.opType) {
|
|
|
|
case 0:
|
|
|
|
message = t("Common:EncryptionFilePreparing");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
message = t("Common:EncryptingFile");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
message = t("Common:LoadingProcessing");
|
|
|
|
}
|
2021-01-20 09:49:14 +00:00
|
|
|
}
|
2022-08-17 08:56:50 +00:00
|
|
|
toastr.info(message);
|
2020-11-19 15:30:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
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() {
|
2022-08-17 08:56:50 +00:00
|
|
|
if (!isSSR)
|
|
|
|
setTimeout(() => {
|
|
|
|
const data = {
|
|
|
|
domain: desktopConstants.domain,
|
|
|
|
onsuccess: "reload",
|
|
|
|
};
|
|
|
|
window.AscDesktopEditor.execCommand(
|
|
|
|
"portal:logout",
|
2023-12-29 11:37:04 +00:00
|
|
|
JSON.stringify(data),
|
2022-08-17 08:56:50 +00:00
|
|
|
);
|
|
|
|
}, 1000);
|
2020-11-12 08:50:21 +00:00
|
|
|
}
|
2020-11-05 11:13:06 +00:00
|
|
|
|
2020-11-12 08:50:21 +00:00
|
|
|
export function checkPwd() {
|
2022-08-17 08:56:50 +00:00
|
|
|
if (!isSSR) {
|
|
|
|
const data = {
|
|
|
|
domain: desktopConstants.domain,
|
|
|
|
emailInput: "login",
|
|
|
|
pwdInput: "password",
|
|
|
|
};
|
|
|
|
window.AscDesktopEditor.execCommand(
|
|
|
|
"portal:checkpwd",
|
2023-12-29 11:37:04 +00:00
|
|
|
JSON.stringify(data),
|
2022-08-17 08:56:50 +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 logout() {
|
2022-08-17 08:56:50 +00:00
|
|
|
if (!isSSR) {
|
|
|
|
const data = {
|
|
|
|
domain: desktopConstants.domain,
|
|
|
|
};
|
|
|
|
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
|
|
|
|
}
|
2020-11-03 06:52:05 +00:00
|
|
|
}
|