jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
833 B

'use strict';
const crypto = require('crypto')
, Captchas = require(__dirname+'/../../db/captchas.js')
, generateCaptcha = require(__dirname+'/../../helpers/captchagenerate.js');
module.exports = async (req, res, next) => {
// if we got here, they dont have a cookie so we need to
// gen a captcha, set their cookie and redirect to the captcha
const text = crypto.randomBytes(20).toString('hex').substring(0,6);
let captchaId;
try {
captchaId = await Captchas.insertOne(text).then(r => r.insertedId); //get id of document as filename and captchaid
await generateCaptcha(text, captchaId);
} catch (err) {
return next(err);
}
return res
.cookie('captchaid', captchaId.toString(), {
'maxAge': 5*60*1000, //5 minute cookie
'httpOnly': true,
'secure': true
})
.redirect(`/captcha/${captchaId}.jpg`);
}