d594d00227
- Fixed theme not being reflected on gallery and admin login pages - Created GlobalThemeProvider to apply themes globally - Updated gallery and admin login pages to use dynamic CSS variables - Added complete translations for all admin sections in English and German: - Notifications management - Event view and creation - Photo upload functionality - Category management - Archive page view - Analytics dashboard - Branding and theme settings - System settings - CMS page management - Email configuration - Fixed admin photo management display issues - Fixed photo upload category assignment - Added password reset functionality for galleries - Improved error handling and user feedback 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const axios = require('axios');
|
|
const { db } = require('../database/db');
|
|
|
|
async function verifyRecaptcha(token) {
|
|
// Check if reCAPTCHA is enabled
|
|
const settings = await db('app_settings')
|
|
.whereIn('setting_key', ['security_enable_recaptcha', 'security_recaptcha_secret_key'])
|
|
.select('setting_key', 'setting_value');
|
|
|
|
const settingsMap = {};
|
|
settings.forEach(setting => {
|
|
try {
|
|
settingsMap[setting.setting_key] = JSON.parse(setting.setting_value);
|
|
} catch (e) {
|
|
settingsMap[setting.setting_key] = setting.setting_value;
|
|
}
|
|
});
|
|
|
|
const isEnabled = settingsMap.security_enable_recaptcha === true ||
|
|
settingsMap.security_enable_recaptcha === 'true';
|
|
const secretKey = settingsMap.security_recaptcha_secret_key;
|
|
|
|
// If reCAPTCHA is not enabled, always return true
|
|
if (!isEnabled) {
|
|
return true;
|
|
}
|
|
|
|
// If enabled but no token provided, fail
|
|
if (!token) {
|
|
return false;
|
|
}
|
|
|
|
// If no secret key configured, log warning but pass
|
|
if (!secretKey) {
|
|
console.warn('reCAPTCHA enabled but no secret key configured');
|
|
return true;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.post(
|
|
'https://www.google.com/recaptcha/api/siteverify',
|
|
null,
|
|
{
|
|
params: {
|
|
secret: secretKey,
|
|
response: token
|
|
}
|
|
}
|
|
);
|
|
|
|
return response.data.success === true;
|
|
} catch (error) {
|
|
console.error('reCAPTCHA verification error:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
module.exports = { verifyRecaptcha }; |