Browse Source

Add automatic and manual reloading of captchas

pull/40/head
discomrade 3 years ago
parent
commit
89b2a8af97
  1. 2
      inc/config.php
  2. 1
      js/ajax.js
  3. 11
      templates/main.js
  4. 4
      templates/post_form.html

2
inc/config.php

@ -1786,7 +1786,7 @@
$config['error']['securimage']=array(
'missing'=>'The captcha field was missing. Please try again',
'empty'=>'Please fill out the captcha',
'bad'=>'Incorrect captcha',
'bad'=>'Incorrect or expired captcha',
);
// Meta keywords. It's probably best to include these in per-board configurations.

1
js/ajax.js

@ -56,6 +56,7 @@ $(window).ready(function() {
return xhr;
},
success: function(post_response) {
reloadCaptcha(); // For securimage captcha. TODO doesn't always need reloading
if (post_response.error) {
if (post_response.banned) {
// You are banned. Must post the form normally so the user can see the ban message.

11
templates/main.js

@ -286,6 +286,17 @@ function dopost(form) {
return form.elements['body'].value != "" || (form.elements['file'] && form.elements['file'].value != "") || (form.elements.file_url && form.elements['file_url'].value != "");
}
function reloadCaptcha() {
// Reload captcha images (date reduces chance of caching)
// If no securimage captcha is enabled, no elements will be found
captchaImgs = document.querySelectorAll('[id=captcha-img]');
for (var i = 0; i < captchaImgs.length; ++i)
captchaImgs[i].src = "/captcha.php?"+Date.now();
captchas = document.querySelectorAll('[id=captcha]');
for (var i = 0; i < captchas.length; ++i)
captchas[i].value = "";
}
function citeReply(id, with_link) {
var textarea = document.getElementById('body');

4
templates/post_form.html

@ -102,8 +102,8 @@
Captcha
</th>
<td>
<img src="{{ config.root }}/captcha.php"><br />
<input type="text" name="captcha" size="25" maxlength="10" autocomplete="off">
<img name="captcha-img" id="captcha-img" src="/captcha.php" onClick="this.src='/captcha.php?'+Date.now();document.getElementById('captcha').value = '';"><br />
<input type="text" name="captcha" id="captcha" size="25" maxlength="10" autocomplete="off">
</td>
</tr>
{% endif %}

Loading…
Cancel
Save