user, post and comment objects contain their ID's now.
This commit is contained in:
@@ -323,6 +323,7 @@ app.post("/submit_post", (req,res) => {
|
|||||||
else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
|
else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
|
||||||
console.log(username, "is submitting a post titled:", title);
|
console.log(username, "is submitting a post titled:", title);
|
||||||
posts.push({
|
posts.push({
|
||||||
|
"id": posts.length,
|
||||||
"userID": func.get_userID(username),
|
"userID": func.get_userID(username),
|
||||||
"title": title,
|
"title": title,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -354,6 +355,7 @@ app.post("/submit_signup", (req,res) => {
|
|||||||
// so this checks that the user does not exist
|
// so this checks that the user does not exist
|
||||||
if (func.get_userID(username) == -1) {
|
if (func.get_userID(username) == -1) {
|
||||||
users.push({
|
users.push({
|
||||||
|
"id": users.length,
|
||||||
"username": username,
|
"username": username,
|
||||||
"prettyname": prettyname,
|
"prettyname": prettyname,
|
||||||
"hash": password,
|
"hash": password,
|
||||||
@@ -398,12 +400,12 @@ app.post("/submit_edit_user", (req,res) => {
|
|||||||
|
|
||||||
if (delete_bool == true) {
|
if (delete_bool == true) {
|
||||||
// Delete the user
|
// Delete the user
|
||||||
users[userID] = {"deleted": true}
|
users[userID] = {"id": userID,"deleted": true}
|
||||||
// Delete all their posts
|
// Delete all their posts
|
||||||
for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
|
for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
|
||||||
if (posts[postid]['userID'] == userID) { // if userID matches
|
if (posts[postid]['userID'] == userID) { // if userID matches
|
||||||
posts[postid] = {"deleted": true} // delete the post
|
posts[postid] = {"id": postid, "deleted": true} // delete the post
|
||||||
comments.comments[postid] = {"deleted": true} // the comments for this post should also be deleted
|
comments.comments[postid] = [] // the comments for this post should also be deleted
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -447,8 +449,8 @@ app.post("/submit_edit_post", (req,res) => {
|
|||||||
post['editdate'] = unix_timestamp
|
post['editdate'] = unix_timestamp
|
||||||
if (typeof delete_bool != "undefined") {
|
if (typeof delete_bool != "undefined") {
|
||||||
console.log("Deleting post!")
|
console.log("Deleting post!")
|
||||||
posts[postID] = {"deleted": true}
|
posts[postID] = {"id": post["id"], "deleted": true}
|
||||||
comments.comments[postID] = {"deleted": true}
|
comments.comments[postID] = [];
|
||||||
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||||
}
|
}
|
||||||
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||||
|
Reference in New Issue
Block a user