diff --git a/README.md b/README.md index 8a9bfb8..0df6e53 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ In action on my website: [deadvey.com](https://deadvey.com)
* hitcount * Markdown syntax in posts * Commenting on posts +* sign up and delete account # Bugs * probably scales like shit @@ -20,8 +21,8 @@ In action on my website: [deadvey.com](https://deadvey.com)
# planned features/todo list * atom * federation (looks tricky) -* sign up * All strings (including in edit and post page) customisable + * formatable custom strings * split code into files to tidy it up a bit * inline comments and docs * give each post a hard postID to prevent potential issues @@ -38,6 +39,7 @@ In action on my website: [deadvey.com](https://deadvey.com)
* %G - Tag name (used for the tag page only) * %H - Frontpage hit count * %I - User description +* %J - URL delete account * %L - URL Permanent link to the post * %M - comments * %N - the username of the user (poster) diff --git a/app.js b/app.js index 7ce98b0..8f2e59d 100755 --- a/app.js +++ b/app.js @@ -152,14 +152,17 @@ function hyperlink_tags(tags) { // See the readme format indicators section for a full list of format indicators // This function replaces the format indicators in a template to the content they represent // accepts the template (string), -// the post index (int) as an optional paramter to indicate what post is to be used (for replacing things like content and titles) +// the post index (int) as an optional paramter to indicate what post is to be used (for replacing things like content and titles of posts) // the tag (strig) as an optional parameter to indicate what tag is being used (for /tag/:tag pages) +// the user index (int) is an optional parameter to indicate what user is to be used (for replacng things like the header of the user page) // returns the template with it's format indiactors replaced (string) function replace_format_indicators(template, post_index=-1, tag_name="tag", user_index=-1) { output_string = template // These should always be replaceable .replaceAll("%%", "%") + .replaceAll("%J", "/delete_account") .replaceAll("%P", "/post") .replaceAll("%O", `/edit/${post_index}`) + .replaceAll("%Q", "/signup") .replaceAll("%R", "/rss") .replaceAll("%Y", config.site_name) .replaceAll("%W", config.site_description) @@ -357,6 +360,13 @@ app.get("/signup", (req,res) => { console.log("Error, invalid value for allow_signup (bool)") } }); // /signup +app.get("/delete_account", (req,res) => { + res.send(`
+
+
+
+
`); +}); // /delete_account app.get("/edit/:post_id", (req,res) => { const post_id = req.params.post_id const post = posts.posts[post_id] @@ -425,7 +435,7 @@ app.post("/submit_post", (req,res) => { } }); // /submit_post app.post("/submit_signup", (req,res) => { - const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); + const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const username = escape_input(req.body.username) const prettyname = escape_input(req.body.prettyname) const description = escape_input(req.body.description) @@ -458,6 +468,39 @@ app.post("/submit_signup", (req,res) => { console.log("Error, invalid value for allow_signup (bool)") } }); // /submit_signup +app.post("/submit_delete_account", (req,res) => { + // Get the form info + const password = crypto.createHash("sha512").update(req.body.password).digest("hex"); + const username = escape_input(req.body.username) + // get the userID + const userID = get_userID(username) + + if (userID >= 0) { // The user exists + if (password == users.users[userID]['hash']) { // password matches + console.log(username, "(userID:", userID, ") is trying deleting their account") + // Delete the user + users.users.splice(userID,1) + // Delete all their posts + for (let postid = 0; postid < posts.posts.length; postid++) { // loop over all posts + if (posts.posts[postid]['userID'] == userID) { // if userID matches + posts.posts.splice(postid,1) // delete the post + comments.comments.splice(postid,1) // the comments for this post should also be delete + } + }; + // Write these changes + fs.writeFileSync(`${__dirname}/users.js`, `export const users = ${JSON.stringify(users.users)}`, 'utf-8'); + fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = ${JSON.stringify(posts.posts)}`, 'utf-8'); + fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = ${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8'); + res.redirect(301,"/") + } + else { // password does not match + res.send(`${config.incorrect_password}`) + }; + } + else { + res.send(`${config.user_doesnt_exist}`) + } +}); // /submit_delete_account app.post("/submit_edit", (req,res) => { const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const postID = req.body.postID diff --git a/hitcount.txt b/hitcount.txt index 495ae25..0642336 100644 --- a/hitcount.txt +++ b/hitcount.txt @@ -1 +1 @@ -464 \ No newline at end of file +473 \ No newline at end of file