Clean up changes
Seperated all routes into seperate files for neatness, and I've made the comments.json store only the comments, comments_counter is in the new data.json file which also stores the hitcount. Signed-off-by: max <deadvey@localhost.localdomain>
This commit is contained in:
58
src/routes/forms.js
Normal file
58
src/routes/forms.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const express = require('express');
|
||||
const config = require('../../config')
|
||||
const data = require('../data')
|
||||
const func = require('../functions')
|
||||
const router = express.Router();
|
||||
|
||||
///////////////////// Form pages ////////////////////////////
|
||||
router.get(config.new_post_url, (req,res) => {
|
||||
res.render("forms/new_post", {
|
||||
config,
|
||||
locale,
|
||||
});
|
||||
}); // /post
|
||||
router.get(config.signup_url, (req,res) => {
|
||||
// if the server does allow signup
|
||||
if (config.allow_signup == true) {
|
||||
// Send the page for signing up to the server
|
||||
res.render("forms/signup", {
|
||||
config,
|
||||
locale,
|
||||
});
|
||||
}
|
||||
// if the server does not allow signup
|
||||
else if (config.allow_signup == false) {
|
||||
res.render("partials/message", {
|
||||
message: locale.signups_unavailable,
|
||||
config,
|
||||
})
|
||||
}
|
||||
// If allow_signup is undefined or not a boolean, error
|
||||
else {
|
||||
res.redirect(301,"/")
|
||||
console.log("Error, invalid value for allow_signup (bool)")
|
||||
}
|
||||
}); // /signup
|
||||
router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => {
|
||||
const userID = parseInt(req.params.user_id);
|
||||
res.render("forms/edit_account", {
|
||||
config,
|
||||
locale,
|
||||
user: users[userID],
|
||||
userID
|
||||
});
|
||||
}); // /delete_account
|
||||
router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
|
||||
const post_id = req.params.post_id
|
||||
const post = posts[post_id]
|
||||
const user = users[post['userID']]
|
||||
res.render("forms/edit_post", {
|
||||
config,
|
||||
locale,
|
||||
post,
|
||||
post_id,
|
||||
user,
|
||||
});
|
||||
}); // /edit/:post_id
|
||||
|
||||
module.exports = router;
|
Reference in New Issue
Block a user