editing user redirects to user's page and began to implment ATOM
This commit is contained in:
@@ -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 "<a href="/tag/string1">string1</a>, <a href="/tag/string2">string2</a>, <a href="/tag/string3">string3</a>"
|
||||
|
@@ -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, "/");
|
||||
|
Reference in New Issue
Block a user