add records to guestbook

This commit is contained in:
b1ek 2023-02-19 17:07:44 +10:00
parent d458f7e249
commit d369f8b7d9
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 49 additions and 8 deletions

View File

@ -1,15 +1,37 @@
const Helpers = require('../helpers'); const Helpers = require('../helpers');
async function handler(req, res) { async function handler(req, res, next) {
try {
res.send(await Helpers.ViewLoader.load('guestbook.pug', { res.send(await Helpers.ViewLoader.load('guestbook.pug', {
current_route: req.originalUrl, current_route: req.originalUrl,
ip: req.ip ip: req.ip,
data: {
// TODO: load from db
1: {
name: 'John Doe',
email: 'a@b.c',
text: 'hiiii',
hidemail: false,
ip: '0.0.0.0',
hidden: false,
time: Date.now()
}
}
})); }));
return; return;
} catch (err) {
next(err);
}
} }
async function submit(req, res) { async function submit(req, res) {
res.send(req.body); const { name, email, message } = req.body;
const hidemail = req.body.hidemail ? (req.body.hidemail == 'on' ? true : false) : false;
res.send({
name, email, message, hidemail
});
return; return;
} }

View File

@ -41,3 +41,22 @@ block content
span(style='font-size:10pt;color:darkred;font-weight:bold'). span(style='font-size:10pt;color:darkred;font-weight:bold').
Warning: Your ip (#{ip}) will be logged and displayed for everyone.<br/> Warning: Your ip (#{ip}) will be logged and displayed for everyone.<br/>
You can delete your own message if it was sent from the same ip for 24 hours after it was sent. You can delete your own message if it was sent from the same ip for 24 hours after it was sent.
hr
if (!data)
p No records available.
else
table
each entry, id in data
tr
td(width='20%' class='gb_sender_data')
p(style='font-size:9pt').
ID: <a id='gb_entry_#{id}' href='#gb_entry_#{id}'>##{id}</a><br/>
Sender: #{entry.name}<br/>
Email: #{entry.email}<br/>
IP: #{entry.ip}<br/>
Date: #{new Date(entry.time).toISOString()}<br/>
td(width='80%' style='padding:0 8px')
p(style='font-size:9pt;font-weight:bold;margin:0;padding:0;padding-top:1em') Message:
p(style='margin:0;padding:0;font-size:10pt').
hiii