Skip to content
Snippets Groups Projects

Resolve "Implement Device Finger Print"

Merged Igor Markin requested to merge 10-implement-device-finger-print into master
All threads resolved!
1 file
+ 35
36
Compare changes
  • Side-by-side
  • Inline
@@ -1347,45 +1347,44 @@ window.currentlyAuthenticatedIdentity = null;
@@ -1347,45 +1347,44 @@ window.currentlyAuthenticatedIdentity = null;
window.currentlyLoadedIdentity = null;
window.currentlyLoadedIdentity = null;
window.lastTimeGetProfile = 0;
window.lastTimeGetProfile = 0;
 
const handleIdentityLogin = (identity, uuid, token) => {
 
const { loadedIdentities, viamApi } = window;
 
 
viamApi.setSessionData(uuid, token);
 
localStorage.setItem("uuid", uuid);
 
localStorage.setItem("token", token);
 
localStorage.setItem("authenticatedIdentity", identity.authentication.publicKey);
 
window.currentlyAuthenticatedIdentity = loadedIdentities[identity.authentication.publicKey];
 
setKeyForUUID(uuid, identity.authentication.publicKey);
 
window.lastTimeGetProfile = 0;
 
};
 
function executeRestfulFunction(type, that, fn, ...args) {
function executeRestfulFunction(type, that, fn, ...args) {
const { currentlyAuthenticatedIdentity, viamApi, loadedIdentities, currentlyLoadedIdentity } = window;
const { currentlyAuthenticatedIdentity, viamApi, currentlyLoadedIdentity } = window;
if (type === "private") {
return new Penpal.Promise(executeResult => {
return new Penpal.Promise(executeResult => {
fn.apply(that, args).then((response) => {
fn.apply(that, args).then((response) => {
const identity = currentlyAuthenticatedIdentity || currentlyLoadedIdentity;
const identity = currentlyAuthenticatedIdentity || currentlyLoadedIdentity;
if (type === "private" && identity && response.data.code === "400" && response.data.status === "Bad session") {
if (response.data.code === "400" && response.data.status === "Bad session" && identity) {
viamApi.identityLogin("previousaddeddevice")
viamApi.identityLogin("previousaddeddevice")
.then((response) => {
.then((response) => {
if (response.data.code === "200") {
if (response.data.code === "200") {
const uuid = response.data.data["Uuid"];
const uuid = response.data.data["Uuid"];
const token = response.data.data["Session"];
const token = response.data.data["Session"];
handleIdentityLogin(identity, uuid, token);
viamApi.setSessionData(uuid, token);
// TODO: Previously there was fn.apply(null, args) where null is probably wrong context for fn.apply()
localStorage.setItem("uuid", uuid);
fn.apply(that, args).then(({data}) => executeResult(data));
localStorage.setItem("token", token);
} else {
localStorage.setItem("authenticatedIdentity", identity.authentication.publicKey);
executeResult(response.data);
window.currentlyAuthenticatedIdentity = loadedIdentities[identity.authentication.publicKey];
}
setKeyForUUID(uuid, identity.authentication.publicKey);
})
window.lastTimeGetProfile = 0;
.catch(console.warn);
fn.apply(null, args).then(({data}) => executeResult(data));
} else {
} else {
executeResult(response.data);
}
})
.catch(console.warn);
} else {
executeResult(response.data);
}
});
});
} else {
return new Penpal.Promise(executeResult => {
fn.apply(that, args).then((response) => {
executeResult(response.data);
executeResult(response.data);
});
}
});
});
}
});
}
}
window.executeRestfulFunction = executeRestfulFunction;
window.executeRestfulFunction = executeRestfulFunction;
Loading