mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-18 17:14:04 +01:00
Add dynamic captcha support
This commit is contained in:
parent
e16dc142b7
commit
e825e7aac5
@ -351,6 +351,15 @@
|
||||
//);
|
||||
$config['simple_spam'] = false;
|
||||
|
||||
/*
|
||||
* If not flase, the captcha is dynamically injected on the client if the web server set the `captcha-required`
|
||||
* cookie to 1. The configuration value should be set the IP for which the captcha should be verified.
|
||||
*
|
||||
* Example:
|
||||
* $config['dynamic_captcha'] = '127.0.0.1'; // Verify the captcha for users sending posts from the loopback address.
|
||||
*/
|
||||
$config['dynamic_captcha'] = false;
|
||||
|
||||
// Enable reCaptcha to make spam even harder. Rarely necessary.
|
||||
$config['recaptcha'] = false;
|
||||
|
||||
|
2
post.php
2
post.php
@ -648,7 +648,7 @@ if (isset($_POST['delete'])) {
|
||||
}
|
||||
}
|
||||
// Remote 3rd party captchas.
|
||||
else {
|
||||
else if (!$config['dynamic_captcha'] || $config['dynamic_captcha'] === $_SERVER['REMOTE_ADDR']) {
|
||||
// recaptcha
|
||||
if ($config['recaptcha']) {
|
||||
if (!isset($_POST['g-recaptcha-response'])) {
|
||||
|
@ -222,6 +222,36 @@ function getCookie(cookie_name) {
|
||||
}
|
||||
}
|
||||
|
||||
{% endraw %}
|
||||
{% if config.dynamic_captcha %}
|
||||
function is_dynamic_captcha_enabled() {
|
||||
let cookie = get_cookie('require-captcha');
|
||||
return cookie === '1';
|
||||
}
|
||||
|
||||
function get_captcha_pub_key() {
|
||||
{% if config.recaptcha %}
|
||||
return "{{ config.recaptcha_public }}";
|
||||
{% else %}
|
||||
return null;
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
function init_dynamic_captcha() {
|
||||
if (!is_dynamic_captcha_enabled()) {
|
||||
let pub_key = get_captcha_pub_key();
|
||||
if (!pub_key) {
|
||||
console.error("Missing public captcha key!");
|
||||
return;
|
||||
}
|
||||
|
||||
let captcha_hook = document.getElementById('captcha');
|
||||
captcha_hook.style = "";
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
{% raw %}
|
||||
|
||||
function highlightReply(id) {
|
||||
if (typeof window.event != "undefined" && event.which == 2) {
|
||||
// don't highlight on middle click
|
||||
|
@ -73,7 +73,11 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% if config.recaptcha %}
|
||||
{% if config.dynamic_captcha %}
|
||||
<tr id="captcha" style="display: none;">
|
||||
{% else %}
|
||||
<tr>
|
||||
{% endif %}
|
||||
<th>
|
||||
{% trans %}Verification{% endtrans %}
|
||||
{{ antibot.html() }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user