mirror of
https://github.com/HeyPuter/puter.git
synced 2026-07-15 03:27:18 +00:00
Merge branch 'main' of https://github.com/HeyPuter/puter
This commit is contained in:
@@ -125,6 +125,9 @@ class PuterHomepageService extends BaseService {
|
||||
login: req.captchaRequired,
|
||||
signup: req.captchaRequired,
|
||||
};
|
||||
|
||||
// cloudflare turnstile site key
|
||||
const turnstileSiteKey = config.services?.['cloudflare-turnstile']?.enabled ? config.services?.['cloudflare-turnstile']?.site_key : null;
|
||||
|
||||
return res.send(this.generate_puter_page_html({
|
||||
env: config.env,
|
||||
@@ -166,8 +169,7 @@ class PuterHomepageService extends BaseService {
|
||||
co_isolation_enabled: req.co_isolation_enabled,
|
||||
// Add captcha requirements to GUI parameters
|
||||
captchaRequired: captchaRequired,
|
||||
// Add Turnstile site key to GUI parameters
|
||||
turnstileSiteKey: config.services?.['cloudflare-turnstile']?.site_key,
|
||||
turnstileSiteKey: turnstileSiteKey,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -22,16 +22,6 @@ import UIWindowLogin from './UIWindowLogin.js'
|
||||
import UIWindowEmailConfirmationRequired from './UIWindowEmailConfirmationRequired.js'
|
||||
import check_password_strength from '../helpers/check_password_strength.js'
|
||||
|
||||
// Helper function to reset Turnstile state
|
||||
const resetTurnstile = (el_window) => {
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset('.cf-turnstile');
|
||||
$(el_window).find('.cf-turnstile').removeAttr('data-token');
|
||||
$(el_window).find('.cf-turnstile').removeClass('captcha-completed');
|
||||
$(el_window).find('.signup-btn').prop('disabled', true);
|
||||
}
|
||||
};
|
||||
|
||||
function UIWindowSignup(options){
|
||||
options = options ?? {};
|
||||
options.reload_on_success = options.reload_on_success ?? true;
|
||||
@@ -89,7 +79,7 @@ function UIWindowSignup(options){
|
||||
// bot trap - if this value is submitted server will ignore the request
|
||||
h += `<input type="text" name="p102xyzname" class="p102xyzname" value="">`;
|
||||
|
||||
// Turnstile widget
|
||||
// Turnstile widget (only when enabled)
|
||||
if(window.gui_params?.turnstileSiteKey){
|
||||
h += `<div style="min-height: 20px; display: flex; justify-content: center;">`;
|
||||
// appearance: always/execute/interaction-only
|
||||
@@ -137,11 +127,9 @@ function UIWindowSignup(options){
|
||||
|
||||
// Initialize Turnstile widget with callback to capture token
|
||||
const initTurnstile = () => {
|
||||
if (window.turnstile) {
|
||||
// Get Turnstile site key from configuration, with fallback
|
||||
const turnstileSiteKey = window.gui_params?.turnstileSiteKey;
|
||||
if (window.turnstile && window.gui_params?.turnstileSiteKey) {
|
||||
window.turnstile.render('.cf-turnstile', {
|
||||
sitekey: turnstileSiteKey,
|
||||
sitekey: window.gui_params.turnstileSiteKey,
|
||||
callback: function(token) {
|
||||
// Store the token for the signup request
|
||||
$(el_window).find('.cf-turnstile').attr('data-token', token);
|
||||
@@ -266,12 +254,15 @@ function UIWindowSignup(options){
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if CAPTCHA was completed
|
||||
const turnstileToken = $(el_window).find('.cf-turnstile').attr('data-token');
|
||||
if (!turnstileToken) {
|
||||
$(el_window).find('.signup-error-msg').html(i18n('captcha_required') || 'Please complete the CAPTCHA verification');
|
||||
$(el_window).find('.signup-error-msg').fadeIn();
|
||||
return;
|
||||
// Check if Cloudflare Turnstile CAPTCHA was completed
|
||||
let turnstileToken = null;
|
||||
if (window.turnstile && window.gui_params?.turnstileSiteKey) {
|
||||
turnstileToken = $(el_window).find('.cf-turnstile').attr('data-token');
|
||||
if (!turnstileToken) {
|
||||
$(el_window).find('.signup-error-msg').html(i18n('captcha_required') || 'Please complete the CAPTCHA verification');
|
||||
$(el_window).find('.signup-error-msg').fadeIn();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//xyzname
|
||||
@@ -325,7 +316,11 @@ function UIWindowSignup(options){
|
||||
$(el_window).find('.signup-btn').prop('disabled', false);
|
||||
|
||||
// Reset Turnstile widget for retry
|
||||
resetTurnstile(el_window);
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset('.cf-turnstile');
|
||||
$(el_window).find('.cf-turnstile').removeAttr('data-token');
|
||||
$(el_window).find('.cf-turnstile').removeClass('captcha-completed');
|
||||
}
|
||||
|
||||
// Process error response
|
||||
const errorText = err.responseText || '';
|
||||
|
||||
Reference in New Issue
Block a user