diff --git a/migrations/20230219070939-create-guestbook.js b/migrations/20230219070939-create-guestbook.js
index 5b761f5..13ca22e 100644
--- a/migrations/20230219070939-create-guestbook.js
+++ b/migrations/20230219070939-create-guestbook.js
@@ -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
}
});
},
diff --git a/models/guestbook.js b/models/guestbook.js
index 2f93f05..f95eb14 100644
--- a/models/guestbook.js
+++ b/models/guestbook.js
@@ -46,7 +46,7 @@ module.exports = (sequelize, DataTypes) => {
}
}, {
sequelize,
- modelName: 'Guestbook',
+ modelName: 'Guestbook'
});
return Guestbook;
};
\ No newline at end of file
diff --git a/models/index.js b/models/index.js
index 43ecfb2..be02043 100644
--- a/models/index.js
+++ b/models/index.js
@@ -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) {
diff --git a/public/static/ui/gb_ui.css b/public/static/ui/gb_ui.css
new file mode 100644
index 0000000..a04187e
--- /dev/null
+++ b/public/static/ui/gb_ui.css
@@ -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
+}
\ No newline at end of file
diff --git a/routes/guestbook.js b/routes/guestbook.js
index ba24ecd..8353b27 100644
--- a/routes/guestbook.js
+++ b/routes/guestbook.js
@@ -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
- });
- // console.log(Sequelize.Guestbook);
+ 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.'));
+
+ res.redirect('/guestbook#gb_entry_' + data.id);
return;
}
diff --git a/view/guestbook.pug b/view/guestbook.pug
index 86fcf76..1413edf 100644
--- a/view/guestbook.pug
+++ b/view/guestbook.pug
@@ -3,6 +3,7 @@ block root
- var title = 'Guestbook'
block head
+
block content
h1 Guestbook
p.
@@ -55,8 +56,8 @@ block content
Sender: #{entry.name}
Email: #{entry.email}
IP: #{entry.ip}
- Date: #{new Date(entry.time).toISOString()}
- 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()}
+ td(width='80%' class='gb_entry_text')
+ p(class='gb_entry_text_title') Message:
p(style='margin:0;padding:0;font-size:10pt').
hiii
\ No newline at end of file
diff --git a/view/layout/main.pug b/view/layout/main.pug
index 9bee7c3..882ca6e 100644
--- a/view/layout/main.pug
+++ b/view/layout/main.pug
@@ -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')