add recaptcha option

This commit is contained in:
2026-05-24 16:44:20 +02:00
parent 393db5fe2a
commit 4a155bc5f4
5 changed files with 76 additions and 1 deletions

View File

@@ -88,7 +88,23 @@ export default (router, tpl) => {
return renderError("Passwords do not match.");
}
// Registration Logic
// reCAPTCHA verification
if (cfg.recaptcha?.enabled && cfg.recaptcha?.secret_key) {
const rcToken = req.post['g-recaptcha-response'];
if (!rcToken) return renderError("Please complete the reCAPTCHA.");
try {
const verifyRes = await fetch('https://www.google.com/recaptcha/api/siteverify', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ secret: cfg.recaptcha.secret_key, response: rcToken, remoteip: ip })
});
const { success } = await verifyRes.json();
if (!success) return renderError("reCAPTCHA verification failed. Please try again.");
} catch (e) {
console.error('[REGISTER] reCAPTCHA error:', e.message);
return renderError("reCAPTCHA check failed. Please try again.");
}
}
let activated = true;
let activationToken = null;

View File

@@ -1092,6 +1092,8 @@ process.on('uncaughtException', err => {
enable_userhall_image_upload: cfg.websrv.enable_userhall_image_upload !== false,
abyss_enabled: cfg.websrv.abyss_enabled !== false,
smtp_enabled: !!(cfg.smtp && cfg.smtp.enabled && cfg.smtp.mail_reset_password),
recaptcha_enabled: !!(cfg.recaptcha && cfg.recaptcha.enabled && cfg.recaptcha.site_key),
recaptcha_site_key: (cfg.recaptcha && cfg.recaptcha.site_key) || '',
show_background_cfg: cfg.websrv.background !== false,
allowed_mimes: Object.keys(cfg.mimes).concat([...new Set(Object.values(cfg.mimes))].map(ext => `.${ext}`)).join(','),
mimes_json: JSON.stringify(cfg.mimes),