bin/routes/main.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-03-04 02:09:05 +01:00
const express = require('express');
const router = express.Router();
const handler = require('express-async-handler');
2023-03-04 06:00:53 +01:00
const content = require('../helpers/content');
2023-03-04 02:09:05 +01:00
2023-04-17 02:37:07 +02:00
const crypto = require('crypto');
2023-03-04 02:09:05 +01:00
async function index(req, res) {
2023-04-17 02:37:07 +02:00
if (!req.session.captcha) {
req.session.captcha = crypto.randomBytes(8).toString('base64').substring(0, 6);
}
2023-04-17 07:23:10 +02:00
req.session.captcha_input = crypto.randomBytes(8).toString('base64').substring(0,crypto.randomInt(10,16));
let fake_fields = [];
const n = crypto.randomInt(10,20);
for (let i = 0; i != n; i++) {
fake_fields.push(crypto.randomBytes(8).toString('base64').substring(0,crypto.randomInt(10,16)))
}
req.session.fake_fields = fake_fields;
2023-04-17 02:37:07 +02:00
if (!req.session.csrf)
req.session.csrf = crypto.randomBytes(10).toString('base64');
2023-03-04 06:00:53 +01:00
res.render('main', {
maxlen: process.env.MAXLEN,
2023-04-17 02:37:07 +02:00
submitted: content.submitted(),
req,
crypto
2023-03-04 06:00:53 +01:00
});
2023-04-17 02:37:07 +02:00
2023-03-04 02:09:05 +01:00
}
router.get('/', handler(index));
module.exports = router;