make preview work with signing

This commit is contained in:
Daniella 2022-05-19 12:40:47 +02:00
parent 17810013c1
commit 13f27a91dc
2 changed files with 14 additions and 9 deletions

View file

@ -45,11 +45,12 @@ 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') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]'), comments: []}
let post = {timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []}
if(fake) {
mainPage.comments.push(post)
res.render('post.ejs', {post: mainPage, postid: '-1', webname: webname, email: email, comment: '', fake: true})
res.render('post.ejs', {post: mainPage, postid: '-1', webname: webname, email: email, comment: '', fake: true, secret: req.body.secret || ''})
} else {
post.content += (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]')
posts.push(post)
res.redirect(`/`)
}
@ -78,12 +79,14 @@ 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') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]'), comments: []})
post.comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
if(fake) {
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake})
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake, secret: req.body.secret || ''})
toRemove = post
} else
} else {
post.content += (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]')
res.redirect(`/post/${id}`)
}
cid = -1
}
return true
@ -105,13 +108,15 @@ 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') + (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]'), 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'), comments: []})
if(fake) {
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake})
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid, fake: fake, secret: req.body.secret || ''})
toRemove = posts[id]
} else
} else {
post.content += (req.body.secret && req.body.secret !== '' ? ('\n\n[* Signed: [" ' + req.body.secret.sha512().sha512().sha256() + ' "] *]') : '\n\n[* Not signed *]')
res.redirect(`/post/${id}`)
}
}
else
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: ''})
}

View file

@ -142,7 +142,7 @@
`<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/>` +
`Signed: <input type="" name="secret" placeholder="Secret text"><br/><br/>` +
`Signed: <input type="" name="secret" placeholder="Secret text" ${fake ? `value="${secret}"` : ''}><br/><br/>` +
`<button type="submit" name="fake" value="no">Submit</button> ` +
`<button type="submit" name="fake" value="yes">Preview</button>` +
`</form></div></post><div>`