add submit button to guestbook

This commit is contained in:
b1ek 2023-02-19 16:05:36 +10:00
parent 9aa8365c2e
commit e69e49fae2
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 47 additions and 3 deletions

View File

@ -1,6 +1,7 @@
// do startup jobs // do startup jobs
require('./startup'); require('./startup');
if (process.env.APP_DEBUG == 'true') process.env.DEBUG = '*/*';
const express = require('express'); const express = require('express');
const app = express(); const app = express();
@ -8,12 +9,15 @@ const session = require('express-session');
const cookie_parse = require('cookie-parser'); const cookie_parse = require('cookie-parser');
const cookie_encrypt = require('cookie-encrypter'); const cookie_encrypt = require('cookie-encrypter');
const Redis = require("ioredis"); const Redis = require("ioredis");
const bodyparser = require('body-parser');
let redisClient = new Redis(process.env.REDIS_PORT, process.env.REDIS_HOST); let redisClient = new Redis(process.env.REDIS_PORT, process.env.REDIS_HOST);
let RedisStore = require("connect-redis")(session) let RedisStore = require("connect-redis")(session)
const { APP_PORT, APP_KEY } = process.env; const { APP_PORT, APP_KEY } = process.env;
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: true }));
app.use(cookie_parse(APP_KEY)) app.use(cookie_parse(APP_KEY))
app.use(cookie_encrypt(APP_KEY)); app.use(cookie_encrypt(APP_KEY));
app.use(session({ app.use(session({

View File

@ -12,6 +12,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"body-parser": "^1.20.1",
"connect-redis": "^6.1.3", "connect-redis": "^6.1.3",
"cookie-encrypter": "^1.0.1", "cookie-encrypter": "^1.0.1",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",

View File

@ -0,0 +1,30 @@
.send_button_1 {
user-select: none;
box-shadow:inset 0px 1px 1px 0px #91b8b3;
background:linear-gradient(to bottom, #768d87 5%, #6c7c7c 100%);
background-color:#768d87;
border-radius:5px;
border:1px solid #566963;
display:inline-block;
cursor:pointer;
color:#1e3038;
font-family:Arial;
font-size:15px;
font-weight:bold;
font-style:italic;
padding:4px 12px;
text-decoration:none;
text-shadow:0px -1px 1px #2b665e;
}
.send_button_1:hover {
background:linear-gradient(to bottom, #6c7c7c 5%, #768d87 100%);
background-color:#6c7c7c;
}
.send_button_1:active {
position:relative;
top:1px;
}
.send_button_1::before {
content: 'send!'
}

View File

@ -8,6 +8,12 @@ async function handler(req, res) {
return; return;
} }
async function submit(req, res) {
res.send(req.body);
return;
}
module.exports = (router) => { module.exports = (router) => {
router.get('/guestbook', handler); router.get('/guestbook', handler);
router.post('/guestbook/submit', submit);
} }

View File

@ -1,6 +1,8 @@
extends layout/main.pug extends layout/main.pug
block root block root
- var title = 'Guestbook' - var title = 'Guestbook'
block head
<link rel='stylesheet' href='/static/ui/send_button.css'>
block content block content
h1 Guestbook h1 Guestbook
p. p.
@ -25,8 +27,9 @@ block content
td td
input(type='checkbox' name='hidemail') input(type='checkbox' name='hidemail')
p(style='margin:6px 0') Your message (512 chars max): p(style='margin:6px 0') Your message (512 chars max):
textarea(name='message' style='width:100%;height:150px') textarea(name='message' style='width:100%;height:150px;max-width:600px;max-height:300px')
p
input(type='submit' class='send_button_1')
td(style='padding:0 16px;margin:0') td(style='padding:0 16px;margin:0')
h5 Guidelines h5 Guidelines
ul ul
@ -34,7 +37,7 @@ block content
li li
| Do not post spam ads, keep it for humans. | Do not post spam ads, keep it for humans.
ul ul
li There is no captcha for a reason. I'd like it to stay like this for as long as possible, so I humbly ask not to ruin it. li There is no captcha for a reason. I'd like to keep it this way for as long as possible, so I humbly ask not to ruin it.
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.