add guestbook entries

This commit is contained in:
b1ek 2023-02-20 01:12:09 +10:00
parent 4f12994bca
commit 7f674379d2
7 changed files with 52 additions and 35 deletions

View File

@ -31,15 +31,8 @@ module.exports = {
allowNull: false
},
time: {
type: DataTypes.BIGINT
},
createdAt: {
allowNull: false,
type: DataTypes.DATE
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE
type: DataTypes.BIGINT,
allowNull: false
}
});
},

View File

@ -46,7 +46,7 @@ module.exports = (sequelize, DataTypes) => {
}
}, {
sequelize,
modelName: 'Guestbook',
modelName: 'Guestbook'
});
return Guestbook;
};

View File

@ -20,8 +20,11 @@ config = {
username: DB_USERNAME || config.username,
password: DB_PASSWORD || config.password,
database: DB_DATABASE || config.database,
host: DB_HOSTNAME || config.host
host: DB_HOSTNAME || config.host,
define: {
timestamps: false
}
};
let sequelize;
if (config.use_env_variable) {

View File

@ -0,0 +1,11 @@
.gb_entry_text {
padding: 0 8px;
vertical-align: middle;
}
.gb_entry_text .gb_entry_text_title {
font-size:9pt;
font-weight:bold;
margin:0;
padding:0;
padding-top:1em
}

View File

@ -3,21 +3,23 @@ const Sequelize = require('../models');
async function handler(req, res, next) {
try {
let data = {};
let sqldata = await Sequelize.Guestbook.findAll({
where: {
hidden: false
}
});
if (!sqldata) throw new Error('Failed to get guestbook entries');
for (let i = 0; i != sqldata.length; i++) {
data[sqldata[i].id] = sqldata[i];
}
res.send(await Helpers.ViewLoader.load('guestbook.pug', {
current_route: req.originalUrl,
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()
}
}
data
}));
return;
} catch (err) {
@ -25,15 +27,22 @@ async function handler(req, res, next) {
}
}
async function submit(req, res) {
async function submit(req, res, next) {
const { name, email, message } = req.body;
const hidemail = req.body.hidemail ? (req.body.hidemail == 'on' ? true : false) : false;
res.send({
name, email, message, hidemail
let data = await Sequelize.Guestbook.create({
name,
email,
text: message,
hidemail,
ip: req.ip,
hidden: false,
time: Math.floor(Date.now() / 1000)
});
if (!data) next(new Error('Failed to create a new record.'));
// console.log(Sequelize.Guestbook);
res.redirect('/guestbook#gb_entry_' + data.id);
return;
}

View File

@ -3,6 +3,7 @@ block root
- var title = 'Guestbook'
block head
<link rel='stylesheet' href='/static/ui/send_button.css'>
<link rel='stylesheet' href='/static/ui/gb_ui.css'>
block content
h1 Guestbook
p.
@ -55,8 +56,8 @@ block content
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:
// Date: #{new Date(entry.time).toISOString()}<br/>
td(width='80%' class='gb_entry_text')
p(class='gb_entry_text_title') Message:
p(style='margin:0;padding:0;font-size:10pt').
hiii

View File

@ -10,14 +10,14 @@ block root
}
doctype html
html
html(style='overflow-y:auto')
head
title blek! Site #{title ? "- " + title : ""}
link(rel='stylesheet' href='/static/main.css')
block head
body
body(style='overflow-y:auto')
table(width='100%' height='100%' class='body_table')
tr
td(class='side_menu')