delete used captchas

merge-requests/208/head
fatchan 5 years ago
parent 8a0160a924
commit 1ca5292660
  1. 7
      db/captchas.js
  2. 2
      gulp/res/css/style.css
  3. 5
      helpers/captchaverify.js
  4. 2
      server.js

@ -18,6 +18,13 @@ module.exports = {
});
},
findOneAndDelete: (id, text) => {
return db.findOneAndDelete({
'_id': id,
'text': text
});
},
deleteAll: () => {
return db.deleteMany({});
},

@ -416,8 +416,8 @@ input[type="file"] {
}
.captcha {
margin: auto;
margin-bottom: 1px;
border: 1px solid #a9a9a9;
}
.postform-label {

@ -23,17 +23,18 @@ module.exports = async (req, res, next) => {
});
}
// try to get the captcha from the DB
let captcha;
try {
const captchaMongoId = Mongo.ObjectId(captchaId);
captcha = await Captchas.findOne(captchaMongoId);
captcha = await Captchas.findOneAndDelete(captchaMongoId, input);
} catch (err) {
return next(err);
}
//check that it exists and matches captcha in DB
if (!captcha || captcha.text !== input) {
if (!captcha || !captcha.value || captcha.value.text !== input) {
return res.status(403).render('message', {
'title': 'Forbidden',
'message': 'Incorrect captcha'

@ -53,7 +53,7 @@ const express = require('express')
// use pug view engine
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views/pages'));
// app.enable('view cache');
app.enable('view cache');
// routes
app.use('/forms', require(__dirname+'/controllers/forms.js'))

Loading…
Cancel
Save