82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
(function () {
|
|
const RegistryApp = (window.RegistryApp = window.RegistryApp || {});
|
|
const store = RegistryApp.store;
|
|
|
|
function sendEvent(event, data) {
|
|
if (
|
|
typeof A3API !== "undefined" &&
|
|
typeof A3API.SendAlert === "function"
|
|
) {
|
|
A3API.SendAlert(
|
|
JSON.stringify({
|
|
event,
|
|
data,
|
|
}),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function getMockPayload() {
|
|
const OrgPortal = window.OrgPortal;
|
|
return {
|
|
session: JSON.parse(JSON.stringify(OrgPortal.data.session)),
|
|
portalData: JSON.parse(JSON.stringify(OrgPortal.data.portalData)),
|
|
};
|
|
}
|
|
|
|
function requestLogin(credentials) {
|
|
store.startLogin();
|
|
|
|
const sent = sendEvent("org::login::request", credentials);
|
|
if (sent) {
|
|
return;
|
|
}
|
|
|
|
window.setTimeout(() => {
|
|
if (!credentials.email || !credentials.password) {
|
|
store.failLogin("Enter both email and password.");
|
|
return;
|
|
}
|
|
|
|
store.completeLogin(getMockPayload());
|
|
}, 350);
|
|
}
|
|
|
|
function receive(eventOrPayload, data = {}) {
|
|
const event =
|
|
typeof eventOrPayload === "object" && eventOrPayload !== null
|
|
? eventOrPayload.event
|
|
: eventOrPayload;
|
|
const payloadData =
|
|
typeof eventOrPayload === "object" && eventOrPayload !== null
|
|
? eventOrPayload.data || {}
|
|
: data;
|
|
|
|
if (event === "org::login::success") {
|
|
store.completeLogin(payloadData);
|
|
return;
|
|
}
|
|
|
|
if (event === "org::login::failure") {
|
|
store.failLogin(payloadData.message || "Authentication failed.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
RegistryApp.bridge = {
|
|
requestLogin,
|
|
receive,
|
|
sendEvent,
|
|
};
|
|
|
|
window.OrgUIBridge = {
|
|
requestLogin,
|
|
receive,
|
|
receiveLoginSuccess: (data) => receive("org::login::success", data),
|
|
receiveLoginFailure: (data) => receive("org::login::failure", data),
|
|
};
|
|
})();
|