Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function checkPro() {
const accountParams = {
fileName: "account.json",
decrypt: true
}
const account = await fetchData(accountParams);
if(account) {
const orgId = JSON.parse(account).orgId;
const { userSession } = getGlobal();
const username = userSession.loadUserData().username;
const pubKey = blockstack.getPublicKeyFromPrivate(userSession.loadUserData().appPrivateKey);
const data = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username
}
const bearer = blockstack.signProfileToken(data, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
return axios.get(`/account/org/${orgId}/user/${username}?pubKey=${pubKey}`, headerObj)
.then(async (res) => {
if(res.data.data) {
return res.data.data;
} else {
return "User not found";
}
}).catch(err => console.log(err));
export function deleteTeamFile(data) {
const { userSession, proOrgInfo } = getGlobal();
const privateKey = userSession.loadUserData().appPrivateKey;
const pubKey = getPublicKeyFromPrivate(privateKey);
const tokenData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey
}
const bearer = blockstack.signProfileToken(tokenData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.delete(`/account/organization/${proOrgInfo.orgId}/teams/${data.teamId}/files/${data.docId}?pubKey=${pubKey}`, headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error(res.data.message);
} else {
await loadData();
ToastsStore.success(`File removed`);
}
const pubKey = blockstack.getPublicKeyFromPrivate(userSession.loadUserData().appPrivateKey);
orgInfo["orgName"] = getGlobal().orgName;
setGlobal({ proOrgInfo: orgInfo });
let orgParams = {
fileName: "account.json",
encrypt: true,
body: JSON.stringify(orgInfo)
}
let postOrgInfo = await postData(orgParams);
console.log(postOrgInfo);
//Then update the DB
const data = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username
}
const bearer = blockstack.signProfileToken(data, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
const orgId = getGlobal().proOrgInfo.orgId;
const url = `/account/org/name/${orgId}`;
const body = {
orgName: getGlobal().orgName,
orgId: getGlobal().proOrgInfo.orgId,
pubKey
}
axios.put(url, JSON.stringify(body), headerObj)
.then((res) => {
name: userSession.encryptContent(getGlobal().name, {publicKey: JSON.parse(fetchedKeys).public}),
teamName: userSession.encryptContent(data.teamName, {publicKey: JSON.parse(fetchedKeys).public}),
orgId: proOrgInfo.orgId,
teamId: data.teamId,
lastUpdated: getMonthDayYear(),
timestamp: Date.now(),
currentHostBucket: userSession.encryptContent(userSession.loadUserData().username, {publicKey: JSON.parse(fetchedKeys).public}),
pubKey: getPublicKeyFromPrivate(privateKey)
}
const tokenData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
}
const bearer = blockstack.signProfileToken(tokenData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.post(`/account/organization/${proOrgInfo.orgId}/files`, JSON.stringify(syncedFile), headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error(res.data.message);
} else {
setGlobal({ teamShare: false, teamListModalOpen: false });
if(data.initialShare === true) {
fileName: "account.json",
encrypt: true,
body: JSON.stringify(getGlobal().proOrgInfo)
}
const updatedAccount = await postData(accountParams);
console.log(updatedAccount);
const privateKey = userSession.loadUserData().appPrivateKey;
userObj["selectedTeam"] = data.selectedTeam;
userObj["pubKey"] = getPublicKeyFromPrivate(privateKey);
userObj["orgId"] = proOrgInfo.orgId;
const jwtData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
}
const bearer = blockstack.signProfileToken(jwtData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.post(`/account/user?updateTeam=${true}`, JSON.stringify(userObj), headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error("Trouble adding new user");
} else {
handleProCheck();
setGlobal({ newTeamMateModalOpen: false })
ToastsStore.success("New user added!");
export async function updateUserInfo(tokenData) {
const { userSession } = getGlobal();
const dataObj = tokenData;
dataObj["username"] = userSession.loadUserData().username;
const privateKey = userSession.loadUserData().appPrivateKey;
dataObj["pubKey"] = getPublicKeyFromPrivate(privateKey);
const jwtData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
}
const bearer = blockstack.signProfileToken(jwtData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.put(`/account/organization/${dataObj.orgId}/user/${dataObj.id}`, JSON.stringify(dataObj), headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error("Trouble updating your account");
} else {
handleProCheck();
ToastsStore.success("Invite accepted!");
localStorage.removeItem('inviteToken');
title: userSession.encryptContent(singleForm.title, {publicKey: JSON.parse(fetchedKeys).public}),
teamName: data.teamName ? userSession.encryptContent(data.teamName, {publicKey: JSON.parse(fetchedKeys).public}) : "",
orgId: proOrgInfo.orgId,
teamId: data.teamId,
lastUpdated: getMonthDayYear(),
timestamp: Date.now(),
responses: singleForm.responses || getGlobal().formResponses,
currentHostBucket: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
}
const tokenData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
}
const bearer = blockstack.signProfileToken(tokenData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.post(`/account/organization/${proOrgInfo.orgId}/forms`, JSON.stringify(syncedForm), headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error(res.data.message);
} else {
setGlobal({ teamShare: false, teamListModalOpen: false });
if(data.initialShare === true) {
ToastsStore.success(`Team form created for team: ${data.teamName}`);
const teams = proOrgInfo.teams;
let myTeams = [];
let teamForms = [];
teams.map(team => {
if(team.users.some(user => user.username === userSession.loadUserData().username)) {
myTeams.push(team);
}
return myTeams;
});
const data = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username
}
const pubKey = getPublicKeyFromPrivate(userSession.loadUserData().appPrivateKey);
const bearer = blockstack.signProfileToken(data, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
for(const team of myTeams) {
await axios.get(`/account/organization/${orgId}/teams/${team.id}/forms?pubKey=${pubKey}`, headerObj)
.then(async (res) => {
if(res.data.data) {
const forms = res.data.data;
//Now we need to fetch the team key
const teamKeyParams = {
fileName: `user/${userSession.loadUserData().username.split('.').join('_')}/team/${team.id}/key.json`,
export async function deleteFromOrg(data) {
const { userSession, proOrgInfo } = getGlobal();
const privateKey = userSession.loadUserData().appPrivateKey;
const pubKey = getPublicKeyFromPrivate(privateKey);
const tokenData = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey
}
const bearer = blockstack.signProfileToken(tokenData, userSession.loadUserData().appPrivateKey);
const headerObj = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': bearer
},
}
axios.delete(`/account/organization/${proOrgInfo.orgId}/users/${data.id}?pubKey=${pubKey}`, headerObj)
.then(async (res) => {
console.log(res.data)
if(res.data.success === false) {
ToastsStore.error(res.data.message);
} else {
await handleProCheck();
ToastsStore.success(`User removed`);