Remove hCaptcha integration from contact form and API route
This commit is contained in:
@@ -26,7 +26,7 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(SubmitContactUseCaseImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(SubmitContactUseCaseImpl.class);
|
||||||
|
|
||||||
private final HCaptchaValidator captchaValidator;
|
//private final HCaptchaValidator captchaValidator;
|
||||||
private final ContactRequestsRepo contactRepository;
|
private final ContactRequestsRepo contactRepository;
|
||||||
private final SendMailUseCase sendMailUseCase; // Inject SendMailUseCase
|
private final SendMailUseCase sendMailUseCase; // Inject SendMailUseCase
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
public SubmitContactUseCaseImpl(HCaptchaValidator captchaValidator,
|
public SubmitContactUseCaseImpl(HCaptchaValidator captchaValidator,
|
||||||
ContactRequestsRepo contactRepository,
|
ContactRequestsRepo contactRepository,
|
||||||
SendMailUseCase sendMailUseCase) {
|
SendMailUseCase sendMailUseCase) {
|
||||||
this.captchaValidator = captchaValidator;
|
//this.captchaValidator = captchaValidator;
|
||||||
this.contactRepository = contactRepository;
|
this.contactRepository = contactRepository;
|
||||||
this.sendMailUseCase = sendMailUseCase;
|
this.sendMailUseCase = sendMailUseCase;
|
||||||
}
|
}
|
||||||
@@ -45,17 +45,17 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
@Override
|
@Override
|
||||||
public ResponseEntity<String> submitContact(ContactRequestDto request) {
|
public ResponseEntity<String> submitContact(ContactRequestDto request) {
|
||||||
log.info("Received contact form from: {}", request.name());
|
log.info("Received contact form from: {}", request.name());
|
||||||
log.debug("Captcha token: {}", request.captcha());
|
//log.debug("Captcha token: {}", request.captcha());
|
||||||
log.info("Message: {}", request.message());
|
log.info("Message: {}", request.message());
|
||||||
|
|
||||||
if (request.email() != null) {
|
if (request.email() != null) {
|
||||||
log.info("Reply to: {} ({})", request.email(), request.name());
|
log.info("Reply to: {} ({})", request.email(), request.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidCaptcha(request.captcha())) {
|
//if (!isValidCaptcha(request.captcha())) {
|
||||||
log.warn("Captcha verification failed for {}", request.email());
|
// log.warn("Captcha verification failed for {}", request.email());
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Captcha verification failed");
|
// return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Captcha verification failed");
|
||||||
}
|
//}
|
||||||
|
|
||||||
ContactRequest message = new ContactRequest()
|
ContactRequest message = new ContactRequest()
|
||||||
.setName(request.name())
|
.setName(request.name())
|
||||||
@@ -80,9 +80,9 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
return ResponseEntity.ok("Contact form submitted successfully");
|
return ResponseEntity.ok("Contact form submitted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidCaptcha(String captcha) {
|
//private boolean isValidCaptcha(String captcha) {
|
||||||
return "10000000-aaaa-bbbb-cccc-000000000001".equals(captcha) || captchaValidator.isValid(captcha);
|
// return "10000000-aaaa-bbbb-cccc-000000000001".equals(captcha) || captchaValidator.isValid(captcha);
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void notifyContactAndTeam(ContactRequestDto request) {
|
private void notifyContactAndTeam(ContactRequestDto request) {
|
||||||
// User confirmation
|
// User confirmation
|
||||||
@@ -96,7 +96,7 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
%s
|
%s
|
||||||
|
|
||||||
Mit freundlichen Grüßen
|
Mit freundlichen Grüßen
|
||||||
Rhein Software
|
Rhein Software Development
|
||||||
""".formatted(request.name(), request.message());
|
""".formatted(request.name(), request.message());
|
||||||
|
|
||||||
// Send confirmation email to user
|
// Send confirmation email to user
|
||||||
@@ -137,4 +137,4 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
|
|||||||
private String safe(String value) {
|
private String safe(String value) {
|
||||||
return value != null ? value : "-";
|
return value != null ? value : "-";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, {useRef, useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
import {motion} from 'framer-motion'
|
import {motion} from 'framer-motion'
|
||||||
import {Button} from '@/components/ui/button'
|
import {Button} from '@/components/ui/button'
|
||||||
import HCaptcha from '@hcaptcha/react-hcaptcha'
|
|
||||||
|
|
||||||
const ContactFormSection = () => {
|
const ContactFormSection = () => {
|
||||||
const captchaRef = useRef<HCaptcha | null>(null)
|
|
||||||
|
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
name: '',
|
name: '',
|
||||||
email: '',
|
email: '',
|
||||||
@@ -17,7 +14,6 @@ const ContactFormSection = () => {
|
|||||||
message: '',
|
message: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const [captchaToken, setCaptchaToken] = useState('')
|
|
||||||
const [submitted, setSubmitted] = useState(false)
|
const [submitted, setSubmitted] = useState(false)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
@@ -33,16 +29,10 @@ const ContactFormSection = () => {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
if (!captchaToken) {
|
|
||||||
setError('Bitte bestätige, dass du kein Roboter bist.')
|
|
||||||
setLoading(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch('/api/contact', {
|
const res = await fetch('/api/contact', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({...form, captcha: captchaToken}),
|
body: JSON.stringify(form),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -55,8 +45,6 @@ const ContactFormSection = () => {
|
|||||||
website: '',
|
website: '',
|
||||||
message: '',
|
message: '',
|
||||||
})
|
})
|
||||||
setCaptchaToken('')
|
|
||||||
captchaRef.current?.resetCaptcha()
|
|
||||||
} else {
|
} else {
|
||||||
const resJson = await res.json()
|
const resJson = await res.json()
|
||||||
setError(
|
setError(
|
||||||
@@ -178,20 +166,6 @@ const ContactFormSection = () => {
|
|||||||
/>
|
/>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
<motion.div
|
|
||||||
className="pt-2"
|
|
||||||
initial={{opacity: 0, y: 10}}
|
|
||||||
whileInView={{opacity: 1, y: 0}}
|
|
||||||
viewport={{once: true}}
|
|
||||||
transition={{duration: 0.5, delay: 0.7}}
|
|
||||||
>
|
|
||||||
<HCaptcha
|
|
||||||
sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
|
|
||||||
onVerify={(token) => setCaptchaToken(token)}
|
|
||||||
ref={captchaRef}
|
|
||||||
/>
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="text-red-600 font-medium pt-2">❌ {error}</div>
|
<div className="text-red-600 font-medium pt-2">❌ {error}</div>
|
||||||
)}
|
)}
|
||||||
@@ -213,4 +187,4 @@ const ContactFormSection = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ContactFormSection
|
export default ContactFormSection
|
||||||
Reference in New Issue
Block a user