const express = require('express'); const router = express.Router(); const handler = require('express-async-handler'); const content = require('../helpers/content'); const crypto = require('crypto'); async function index(req, res) { if (!req.session.captcha) { req.session.captcha = crypto.randomBytes(8).toString('base64').substring(0, 6); } 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; if (!req.session.csrf) req.session.csrf = crypto.randomBytes(10).toString('base64'); res.render('main', { maxlen: process.env.MAXLEN, submitted: content.submitted(), req, crypto }); } router.get('/', handler(index)); module.exports = router;