Files
blogger-nodejs/src/routes/forms.js
deadvey 3d58c5b244 Some minor changes to data handling error messages
and fixed a issue occuring in the forms routs that used the old
parameters for data.getdata
2025-11-30 17:04:15 +00:00

59 lines
1.7 KiB
JavaScript

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: data.getdata('users', 'id', userID),
userID
});
}); // /delete_account
router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
const postID = req.params.post_id
const post = data.getdata('posts','id', postID)
const user = data.getdata('users', 'id', post.userID)
res.render("forms/edit_post", {
config,
locale,
post,
postID,
user,
});
}); // /edit/:post_id
module.exports = router;