11import { form , getRequestEvent , query } from '$app/server' ;
2+ import { validateTurnstile } from '$lib/server/turnstile' ;
23import { fail } from '@sveltejs/kit' ;
34import z from 'zod' ;
45
@@ -45,12 +46,13 @@ const ContanctSubmissionSchema = z.object({
4546 // Actual fields
4647 namekjkj : z . string ( ) . min ( 1 , 'Name is required' ) ,
4748 emailkjkj : z . email ( 'Invalid email address' ) ,
48- messagekjkj : z . string ( ) . min ( 1 , 'Message is required' )
49+ messagekjkj : z . string ( ) . min ( 1 , 'Message is required' ) ,
50+ 'cf-turnstile-response' : z . string ( ) . min ( 1 , 'CAPTCHA verification is required' )
4951} ) ;
5052
5153export const createContactSubmissionAction = form (
5254 ContanctSubmissionSchema ,
53- async ( { name, email, namekjkj, emailkjkj, messagekjkj } ) => {
55+ async ( { name, email, namekjkj, emailkjkj, messagekjkj, 'cf-turnstile-response' : token } ) => {
5456 const event = getRequestEvent ( ) ;
5557 const { locals, getClientAddress } = event ;
5658 const ip = getClientAddress ( ) ;
@@ -61,6 +63,12 @@ export const createContactSubmissionAction = form(
6163 return fail ( 400 , { success : false } ) ;
6264 }
6365
66+ const validation = await validateTurnstile ( token , ip ) ;
67+ if ( ! validation . success ) {
68+ console . log ( `[ContactForm] 🚫 Turnstile validation failed from IP: ${ ip } ` ) ;
69+ return fail ( 400 , { success : false , error : 'CAPTCHA verification failed' } ) ;
70+ }
71+
6472 // Check for spam in message content
6573 if ( isSpamMessage ( messagekjkj ) ) {
6674 console . log ( `[ContactForm] 🚫 Spam detected from IP: ${ ip } ` ) ;
0 commit comments