add signatures

This commit is contained in:
Daniella / Tove 2022-05-19 12:09:29 +02:00
parent 6bdaa03b7f
commit 08bb1985b1
3 changed files with 9 additions and 5 deletions

View file

@ -1,3 +1,5 @@
require('hashcode.js')
const Express = require('express')
const bdb = require('bdb.js')
const posts = bdb.load('posts.json', 1)
@ -43,7 +45,7 @@ server.all('/', function get(req, res) {
mainPage.comments.push({timestamp: posts[i].timestamp, author: posts[i].author, title: posts[i].title, content: posts[i].content, comments: []})
}
if(req.body.name && req.body.title && req.body.content) {
let post = {timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []}
let post = {timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : ''), comments: []}
if(fake) {
mainPage.comments.push(post)
res.render('post.ejs', {post: mainPage, postid: '-1', webname: webname, email: email, comment: '', fake: true})
@ -76,7 +78,7 @@ server.all('/comment', function get(req, res) {
console.log(String(cid) + ' ' + comment)
if(String(cid) === comment) {
if(req.body.name && req.body.title && req.body.content) {
post.comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
post.comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : ''), comments: []})
if(fake) {
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake})
toRemove = post
@ -103,7 +105,7 @@ server.all('/comment', function get(req, res) {
}
else {
if(req.body.name && req.body.title && req.body.content) {
posts[id].comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
posts[id].comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : ''), comments: []})
if(fake) {
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake})
toRemove = posts[id]

View file

@ -12,6 +12,7 @@
"bdb.js": "^0.3.2-c",
"body-parser": "^1.19.1",
"ejs": "^3.1.6",
"express": "^4.17.2"
"express": "^4.17.2",
"hashcode.js": "^2.2.1"
}
}

View file

@ -141,7 +141,8 @@
`</h3>` +
`<textarea id=edit name="content" placeholder="So basically, ..." required>` +
(fake ? post.comments[post.comments.length - 1].content.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;") : '') +
`</textarea><br/><br/>` +
`</textarea><br/>` +
`Signed: <input type="" name="secret" placeholder="Secret text"><br/><br/>` +
`<button type="submit" name="fake" value="no">Submit</button> ` +
`<button type="submit" name="fake" value="yes">Preview</button>` +
`</form></div></post><div>`