Auto remove captcha field if its no longer needed close #284

merge-requests/208/head
Thomas Lynch 4 years ago
parent 46bb8870e9
commit 6740d4d529
  1. 10
      gulp/res/js/captcha.js
  2. 6
      gulp/res/js/forms.js
  3. 3
      models/forms/makepost.js

@ -80,6 +80,16 @@ class CaptchaController {
xhr.send(null);
}
removeCaptcha() {
const postForm = document.getElementById('postform');
const captchaField = postForm.querySelector('.captcha');
if (captchaField) {
//delete the whole row
const captchaRow = captchaField.closest('.row');
captchaRow.remove();
}
}
addMissingCaptcha() {
const postSubmitButton = document.getElementById('submitpost');
const captchaFormSectionHtml = captchaformsection({ captchaGridSize });

@ -74,7 +74,6 @@ class formHandler {
this.enctype = this.form.getAttribute('enctype');
this.messageBox = form.querySelector('#message');
this.captchaField = form.querySelector('.captchafield') || form.querySelector('.g-recaptcha') || form.querySelector('.h-captcha');
this.submit = form.querySelector('input[type="submit"]');
if (this.submit) {
this.originalSubmitText = this.submit.value;
@ -174,6 +173,11 @@ class formHandler {
} else if(captchaResponse && hcaptcha) {
hcaptcha.reset();
}
if (xhr.getResponseHeader('x-captcha-enabled') === 'false') {
//remove captcha if it got disabled after you opened the page
captchaController.removeCaptcha();
this.captchaField = null;
}
this.submit.disabled = false;
this.submit.value = this.originalSubmitText;
let json;

@ -553,6 +553,9 @@ module.exports = async (req, res, next) => {
'board': res.locals.board
};
//let frontend script know if captcha is still enabled
res.set('x-captcha-enabled', captchaMode > 0);
if (req.headers['x-using-live'] != null && data.thread) {
//defer build and post will come live
res.json({

Loading…
Cancel
Save