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: () => { deleteAll: () => {
return db.deleteMany({}); return db.deleteMany({});
}, },

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

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

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

Loading…
Cancel
Save