diff --git a/javascript/src/constants/statuses.js b/javascript/src/constants/statuses.js index 856d7c47f82097c8156b9f08e235e8a50a0a19c2..c835b77a2349bb1d3ebe1e7394efef007fc03de1 100644 --- a/javascript/src/constants/statuses.js +++ b/javascript/src/constants/statuses.js @@ -1,2 +1,3 @@ export const STATUS_DEVICE_REVOKED = "Device revoked"; -export const STATUS_USER_NOT_ACTIVATED = 'User not activated'; +export const STATUS_USER_NOT_ACTIVATED = "User not activated"; +export const STATUS_USER_BLOCKED = "User blocked"; diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index f82a7e7bc1b6c1896f20cc7703d4c0f16569f5a7..8fe7f0c4c32f216d3020a756385b553eaabe0a53 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1,4 +1,4 @@ -import '../lib/textencoder.polyfill'; +import "../lib/textencoder.polyfill"; import { parseSMIME, prepareVCardParts } from "../utilities/emailUtilities"; import { stringToUtf8ByteArray, @@ -37,7 +37,8 @@ import CryptoData from "../CryptoData"; import Identity from "../Identity"; import { STATUS_DEVICE_REVOKED, - STATUS_USER_NOT_ACTIVATED + STATUS_USER_NOT_ACTIVATED, + STATUS_USER_BLOCKED } from "../constants/statuses"; import generateQrCode from "../utilities/generateQrCode"; @@ -323,12 +324,12 @@ async function executeRestfulFunction(type, that, fn, config, ...args) { const userNotActivated = type === "private" && code === "400" && - status === STATUS_USER_NOT_ACTIVATED; + (status === STATUS_USER_NOT_ACTIVATED || status === STATUS_USER_BLOCKED); if (userNotActivated) { destroyIdentity(); - const event = createEvent("", "UserNotActivated"); + const event = createEvent("", "UserBlocked"); iframeParent.onEvent(event); return response.data; @@ -339,13 +340,17 @@ async function executeRestfulFunction(type, that, fn, config, ...args) { identity && code === "400" && status === "Bad session"; - if (!badSession) { return response.data; } + if (!badSession) { + return response.data; + } const loginResponse = await viamApi.identityLogin( null, "previousaddeddevice" ); - if (loginResponse.data.code !== "200") { return loginResponse.data; } + if (loginResponse.data.code !== "200") { + return loginResponse.data; + } const uuid = loginResponse.data.data["Uuid"]; const token = loginResponse.data.data["Session"]; @@ -417,15 +422,13 @@ function loadIdentityInternal(identityKey, pinCode) { function getCertificateForPassport(passportUUID, internal) { return new Penpal.Promise(certificateResult => { if (window.currentlyAuthenticatedIdentity === null) { - return { data: "", - code: "400", - status: "Identity not authenticated" }; + return { data: "", code: "400", status: "Identity not authenticated" }; } const passportIdentity = window.currentlyAuthenticatedIdentity; const passport = passportIdentity.getPassport(passportUUID); if (passport === undefined || passport === null) { - createPassportCertificate(passportUUID).then(function (keys) { + createPassportCertificate(passportUUID).then(function(keys) { const cryptoData = new CryptoData(); cryptoData.setPublicKey(keys["publicKeyPEM"]); cryptoData.setPrivateKey(keys["privateKeyPEM"]); @@ -536,14 +539,14 @@ const connection = Penpal.connectToParent({ window.WOPI_URL = wopiUrl.charAt(wopiUrl.length - 1) === "/" ? wopiUrl : wopiUrl + "/"; window.COLLABORA_URL = - collaboraUrl.charAt(collaboraUrl.length - 1) === "/" ? - collaboraUrl : - collaboraUrl + "/"; + collaboraUrl.charAt(collaboraUrl.length - 1) === "/" + ? collaboraUrl + : collaboraUrl + "/"; }, ...penpalMethods, createIdentity(pinCode) { return new Penpal.Promise(result => { - createPassportCertificate(makeid()).then(function (keys) { + createPassportCertificate(makeid()).then(function(keys) { const newIdentity = new Identity(); const cryptoData = new CryptoData(); cryptoData.setPublicKey(keys["publicKeyPEM"]); @@ -578,9 +581,7 @@ const connection = Penpal.connectToParent({ listIdentities() { return new Penpal.Promise(result => { const identities = listIdentitiesFromLocalStorage(); - result({ data: identities, - code: "200", - status: "Identities listed" }); + result({ data: identities, code: "200", status: "Identities listed" }); }); }, loadIdentity(identityKey, pinCode) { @@ -627,9 +628,7 @@ const connection = Penpal.connectToParent({ "profiles/" + identityKey ); if (serializedProfile === null || serializedProfile === "") { - result({ data: "", - code: "400", - status: "Profile is empty" }); + result({ data: "", code: "400", status: "Profile is empty" }); } else { result({ data: JSON.parse(serializedProfile), @@ -855,7 +854,7 @@ const connection = Penpal.connectToParent({ if (executeResult.code === "200") { const actionID = executeResult.data["ActionID"]; const QrCode = executeResult.data["QrCode"]; - QRCode.toDataURL(actionID + "," + QrCode, function (err, url) { + QRCode.toDataURL(actionID + "," + QrCode, function(err, url) { executeResult.data["image"] = url; result(executeResult); }); @@ -967,14 +966,10 @@ const connection = Penpal.connectToParent({ "authenticatedIdentity" ); if (authenticationPublicKey === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } if (window.loadedIdentities[authenticationPublicKey] === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } const success = extendPinCodeTtl(authenticationPublicKey); @@ -988,9 +983,7 @@ const connection = Penpal.connectToParent({ } if (localStorage.getItem("uuid") === null) { - result({ data: "", - code: "400", - status: "Not logged in UUID" }); + result({ data: "", code: "400", status: "Not logged in UUID" }); } result({ data: localStorage.getItem("uuid"), @@ -1005,14 +998,10 @@ const connection = Penpal.connectToParent({ "authenticatedIdentity" ); if (authenticationPublicKey === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } if (window.loadedIdentities[authenticationPublicKey] === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } const success = extendPinCodeTtl(authenticationPublicKey); @@ -1038,14 +1027,10 @@ const connection = Penpal.connectToParent({ "authenticatedIdentity" ); if (authenticationPublicKey === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } if (window.loadedIdentities[authenticationPublicKey] === null) { - return { data: "", - code: "400", - status: "Identity not loaded" }; + return { data: "", code: "400", status: "Identity not loaded" }; } const success = extendPinCodeTtl(authenticationPublicKey); @@ -1071,7 +1056,7 @@ const connection = Penpal.connectToParent({ emailArg, passportPrivateKey, passportCertificate - ).then(function (keys) { + ).then(function(keys) { const publicKeyOneTime = keys["publicKeyPEM"]; const privateKeyOneTime = keys["privateKeyPEM"]; const certificateOneTime = keys["certificatePEM"]; @@ -2173,7 +2158,7 @@ connection.promise.then(parent => { let previousLocalStorageToken; let previousLocalStorageIdentity; - setInterval(async function () { + setInterval(async function() { if (window.currentlyAuthenticatedIdentity) { const { authentication } = window.currentlyAuthenticatedIdentity; const pinCode = getPincode(authentication.publicKey); @@ -2306,7 +2291,7 @@ connection.promise.then(parent => { const eventCopy = JSON.parse(JSON.stringify(event)); - QRCode.toDataURL(actionID + "," + QrCode, function (err, url) { + QRCode.toDataURL(actionID + "," + QrCode, function(err, url) { eventCopy["payloads"].push(url); parent.onEvent(eventCopy); }); @@ -2379,7 +2364,7 @@ connection.promise.then(parent => { const eventCopy = JSON.parse(JSON.stringify(event)); - QRCode.toDataURL(actionID + "," + QrCode, function (err, url) { + QRCode.toDataURL(actionID + "," + QrCode, function(err, url) { eventCopy["payloads"].push(url); parent.onEvent(eventCopy); }); @@ -2427,7 +2412,7 @@ connection.promise.then(parent => { const eventCopy = JSON.parse(JSON.stringify(event)); - QRCode.toDataURL(actionID + "," + QrCode, function (err, url) { + QRCode.toDataURL(actionID + "," + QrCode, function(err, url) { eventCopy["payloads"].push(url); parent.onEvent(eventCopy); });