diff --git a/README.md b/README.md index bca1e41..073612d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ Read the [configuation guide](docs/CONFIG.md) for configuration help (in config. * probably insecure as hell # Planned features/todo list -* edit user (could be on instead of the delete_account page) * user specific RSS feeds * atom * federation (looks tricky) @@ -41,6 +40,8 @@ Read the [configuation guide](docs/CONFIG.md) for configuration help (in config. * inline comments and docs * clean up code a bit * comment pages? +* /postID and /userID pages +* site index TODO (not finished) # EJS variable names diff --git a/data/example-config.json b/data/example-config.json index 6f0005c..6569884 100755 --- a/data/example-config.json +++ b/data/example-config.json @@ -10,13 +10,13 @@ "enable_hitcount": true, "charset": "UTF-8", "root_path": "/home/deadvey/code/web/blogger-webroot/", - "delete_account_url": "/delete_account", + "edit_account_base_url": "/edit_account", "new_post_url": "/post", "signup_url": "/signup", "edit_post_base_url": "/edit", "default_comenter_username": "Anon", "rss": true, - "rss_url": "/rss", + "atom": true, "date_format": "yyyy-MM-dd", "time_zone": "+0000", "string": { @@ -24,7 +24,7 @@ "signups_unavailable": "Sorry, this server does not allow signups", "user_exists": "Sorry, this user already exists, try a different username", "user_doesnt_exist": "Sorry, this user does not exist", - "delete_account_confirmation": "I agree that my account and all of my posts will be permanently deleted instantly", + "delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)", "incorrect_password": "Incorrect Password", "rss_disabled": "Sorry, RSS is disabled", "attribution": "Powered by blogger-nodejs: Source Code, license (WTFPL)" diff --git a/example-config.json b/example-config.json index f61ab21..e044268 100755 --- a/example-config.json +++ b/example-config.json @@ -10,13 +10,13 @@ "enable_hitcount": true, "charset": "UTF-8", "root_path": "/path/to/blogger-webroot", - "delete_account_url": "/delete_account", + "edit_account_base_url": "/edit_account", "new_post_url": "/post", "signup_url": "/signup", "edit_post_base_url": "/edit", "default_comenter_username": "Anon", "rss": true, - "rss_url": "/rss", + "atom": true, "date_format": "yyyy-MM-dd", "time_zone": "+0000", "string": { diff --git a/src/functions.js b/src/functions.js index cc5f6e8..d5db46c 100644 --- a/src/functions.js +++ b/src/functions.js @@ -25,6 +25,13 @@ export function unix_time_to_rss_date(unix_time) { let formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss") return `${formatted_date} ${config.time_zone}` } +// And again with atom's date format +export function unix_time_to_atom_date(unix_time) { + const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library + let date = fromUnixTime(unix_time) + let formatted_date = format(date, "yyyy-MM-dd\\THH:mm:ss\\Z") + return `${formatted_date}` +} // This function accepts a list of strings eg ["string1","string2,"string3"] (any length) // then returns a string of them each pointing to a seperate url // eg "string1, string2, string3" diff --git a/src/server.js b/src/server.js index b91b9fa..5b6649f 100644 --- a/src/server.js +++ b/src/server.js @@ -61,7 +61,7 @@ app.set('views', '../views') ////////////////////// SYNDICATION //////////////////////// // RSS protocol gets -app.get(config.rss_url, (req,res) => { +app.get("/rss", (req,res) => { if (config.rss == false) { res.render("partials/message", { message: config.string.rss_disabled, @@ -70,7 +70,25 @@ app.get(config.rss_url, (req,res) => { } else { res.setHeader('content-type', 'application/rss+xml'); - res.render("syndication/rss", { + res.render("syndication/global_rss", { + config, + posts, + converter, + func, + }) + }; +}); +// ATOM protocol gets +app.get("/atom", (req,res) => { + if (config.rss == false) { + res.render("partials/message", { + message: config.string.rss_disabled, + config: config, + }) + } + else { + res.setHeader('content-type', 'application/rss+xml'); + res.render("syndication/global_atom", { config, posts, converter, @@ -183,8 +201,9 @@ app.get(config.signup_url, (req,res) => { console.log("Error, invalid value for allow_signup (bool)") } }); // /signup -app.get(config.delete_account_url, (req,res) => { - res.render("forms/delete_account", { config }); +app.get(`${config.edit_account_base_url}/:user_id`, (req,res) => { + const userID = parseInt(req.params.user_id); + res.render("forms/edit_account", { config, user: users[userID], userID }); }); // /delete_account app.get(`${config.edit_post_base_url}/:post_id`, (req,res) => { const post_id = req.params.post_id @@ -295,30 +314,36 @@ app.post("/submit_signup", (req,res) => { console.log("Error, invalid value for allow_signup (bool)") } }); // /submit_signup -app.post("/submit_delete_account", (req,res) => { +app.post("/submit_edit_user", (req,res) => { // Get the form info const password = crypto.createHash("sha512").update(req.body.password).digest("hex"); - const username = func.escape_input(req.body.username) - // get the userID - const userID = func.get_userID(username) + const userID = func.escape_input(req.body.userID) + const description = func.escape_input(req.body.description) + const prettyname = func.escape_input(req.body.prettyname) + const delete_bool = req.body.delete if (userID >= 0) { // The user exists if (password == users[userID]['hash']) { // password matches - console.log(username, "(userID:", userID, ") is trying deleting their account") - // Delete the user - users[userID] = {"deleted": true} - // Delete all their posts - for (let postid = 0; postid < posts.length; postid++) { // loop over all posts - if (posts[postid]['userID'] == userID) { // if userID matches - posts[postid] = {"deleted": true} // delete the post - comments.comments[postid] = {"deleted": true} // the comments for this post should also be deleted - } - }; + console.log(userID, " (userID) is modifying their account") + users[userID]["prettyname"] = prettyname; + users[userID]["description"] = description; + + if (delete_bool == true) { + // Delete the user + users[userID] = {"deleted": true} + // Delete all their posts + for (let postid = 0; postid < posts.length; postid++) { // loop over all posts + if (posts[postid]['userID'] == userID) { // if userID matches + posts[postid] = {"deleted": true} // delete the post + comments.comments[postid] = {"deleted": true} // the comments for this post should also be deleted + } + }; + } // Write these changes fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8'); fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); - res.redirect(301,"/") + res.redirect(301,`/user/${users[userID]["username"]}`) } else { // password does not match res.render("partials/message", { @@ -335,7 +360,7 @@ app.post("/submit_delete_account", (req,res) => { }) } }); // /submit_delete_account -app.post("/submit_edit", (req,res) => { +app.post("/submit_edit_post", (req,res) => { const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const postID = req.body.postID const userID = req.body.userID @@ -356,7 +381,7 @@ app.post("/submit_edit", (req,res) => { console.log("Deleting post!") posts[postID] = {"deleted": true} comments.comments[postID] = {"deleted": true} - fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8'); + fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); } fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); res.redirect(302, "/"); diff --git a/views/forms/delete_account.ejs b/views/forms/delete_account.ejs deleted file mode 100644 index b65ce4d..0000000 --- a/views/forms/delete_account.ejs +++ /dev/null @@ -1,14 +0,0 @@ - - - - -
-
-
-
-
-
- - diff --git a/views/forms/edit_account.ejs b/views/forms/edit_account.ejs new file mode 100644 index 0000000..1ba4ca6 --- /dev/null +++ b/views/forms/edit_account.ejs @@ -0,0 +1,16 @@ + + + + +
+ +
+
+
+
+
+
+ + diff --git a/views/forms/edit_post.ejs b/views/forms/edit_post.ejs index a2ac191..59a5ecd 100644 --- a/views/forms/edit_post.ejs +++ b/views/forms/edit_post.ejs @@ -4,7 +4,7 @@ <%- include("../partials/head") %> -
+
diff --git a/views/headers/timeline.ejs b/views/headers/timeline.ejs index ac93ec0..d289f0b 100644 --- a/views/headers/timeline.ejs +++ b/views/headers/timeline.ejs @@ -7,7 +7,6 @@ RSS Feed
New post
Sign Up
-Delete Account
<% if (config.enable_hitcount == true) { %> Hitcount: <%= hitcount %> <% } %> diff --git a/views/headers/user.ejs b/views/headers/user.ejs index cdc6f55..23c8636 100644 --- a/views/headers/user.ejs +++ b/views/headers/user.ejs @@ -2,4 +2,5 @@ <%= user.prettyname %>'s posts

<%- converter.makeHtml(user.description) %>

+edit account <%- config.seperator %> diff --git a/views/syndication/global_atom.ejs b/views/syndication/global_atom.ejs new file mode 100644 index 0000000..1c170af --- /dev/null +++ b/views/syndication/global_atom.ejs @@ -0,0 +1,8 @@ +" ?> + + <%= config.site_name %> + <%= config.site_url %> + <%= config.site_description %> + <%= new Date() %> + <%= config.site_url %> + diff --git a/views/syndication/global_rss.ejs b/views/syndication/global_rss.ejs new file mode 100644 index 0000000..73e43e6 --- /dev/null +++ b/views/syndication/global_rss.ejs @@ -0,0 +1,20 @@ +" ?> + + + <%= config.site_name %> + <%= config.site_url %> + <%= config.site_description %> + <% for (let postID = posts.length-1; postID >= 0; postID--) { %> + + <%= posts[postID]["title"] %> + <%= config.site_url %>/post/<%= postID %> + ]]> + <%= config.site_url %>/post/<%= postID %> + <%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %> + <% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %> + ]]> + <% } %> + + <% } %> + +