Compare commits
4 Commits
release-1.
...
246303139d
| Author | SHA1 | Date | |
|---|---|---|---|
| 246303139d | |||
| 1e09420705 | |||
| cc495f3b87 | |||
| 570f5d44f5 |
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
@@ -334,13 +334,6 @@ stage('SonarQube Quality Gate') {
|
|||||||
|
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -a
|
|
||||||
. /opt/furious-ducks/secrets/tiptop-mail.env
|
|
||||||
set +a
|
|
||||||
|
|
||||||
test -n "${TURNSTILE_SITE_KEY}"
|
|
||||||
echo "Turnstile site key chargée (longueur: ${#TURNSTILE_SITE_KEY})"
|
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
-t "${BACKEND_IMAGE}:${IMAGE_TAG}" \
|
-t "${BACKEND_IMAGE}:${IMAGE_TAG}" \
|
||||||
backend
|
backend
|
||||||
|
|||||||
@@ -1,124 +1,19 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { Turnstile } from '@marsidev/react-turnstile'
|
||||||
import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha'
|
import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha'
|
||||||
|
|
||||||
const TURNSTILE_SCRIPT_ID = 'cf-turnstile-script'
|
// `ref` expose reset() : un jeton Turnstile n'est valable qu'une fois, il faut
|
||||||
const TURNSTILE_SCRIPT_URL =
|
// en redemander un après chaque envoi refusé.
|
||||||
'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'
|
export default function Captcha({ ref, onToken }) {
|
||||||
|
if (!CAPTCHA_ENABLED) return null
|
||||||
export default function Captcha({ onToken }) {
|
|
||||||
const containerRef = useRef(null)
|
|
||||||
const widgetIdRef = useRef(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!CAPTCHA_ENABLED || !TURNSTILE_SITE_KEY || !containerRef.current) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let cancelled = false
|
|
||||||
|
|
||||||
const renderWidget = () => {
|
|
||||||
if (
|
|
||||||
cancelled ||
|
|
||||||
!containerRef.current ||
|
|
||||||
!window.turnstile
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (widgetIdRef.current !== null) {
|
|
||||||
try {
|
|
||||||
window.turnstile.remove(widgetIdRef.current)
|
|
||||||
} catch {
|
|
||||||
// Widget déjà supprimé
|
|
||||||
}
|
|
||||||
|
|
||||||
widgetIdRef.current = null
|
|
||||||
}
|
|
||||||
|
|
||||||
containerRef.current.innerHTML = ''
|
|
||||||
|
|
||||||
widgetIdRef.current = window.turnstile.render(
|
|
||||||
containerRef.current,
|
|
||||||
{
|
|
||||||
sitekey: TURNSTILE_SITE_KEY,
|
|
||||||
language: 'fr',
|
|
||||||
size: 'flexible',
|
|
||||||
appearance: 'always',
|
|
||||||
|
|
||||||
callback: (token) => {
|
|
||||||
onToken(token)
|
|
||||||
},
|
|
||||||
|
|
||||||
'expired-callback': () => {
|
|
||||||
onToken('')
|
|
||||||
},
|
|
||||||
|
|
||||||
'error-callback': () => {
|
|
||||||
onToken('')
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingScript = document.getElementById(
|
|
||||||
TURNSTILE_SCRIPT_ID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (window.turnstile) {
|
|
||||||
renderWidget()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingScript) {
|
|
||||||
existingScript.addEventListener('load', renderWidget, {
|
|
||||||
once: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cancelled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const script = document.createElement('script')
|
|
||||||
|
|
||||||
script.id = TURNSTILE_SCRIPT_ID
|
|
||||||
script.src = TURNSTILE_SCRIPT_URL
|
|
||||||
script.async = true
|
|
||||||
script.defer = true
|
|
||||||
|
|
||||||
script.addEventListener('load', renderWidget, {
|
|
||||||
once: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
document.head.appendChild(script)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cancelled = true
|
|
||||||
|
|
||||||
if (
|
|
||||||
widgetIdRef.current !== null &&
|
|
||||||
window.turnstile
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
window.turnstile.remove(widgetIdRef.current)
|
|
||||||
} catch {
|
|
||||||
// Widget déjà supprimé
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
widgetIdRef.current = null
|
|
||||||
}
|
|
||||||
}, [onToken])
|
|
||||||
|
|
||||||
if (!CAPTCHA_ENABLED || !TURNSTILE_SITE_KEY) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<Turnstile
|
||||||
ref={containerRef}
|
ref={ref}
|
||||||
id="turnstile-captcha"
|
siteKey={TURNSTILE_SITE_KEY}
|
||||||
className="w-full min-h-[65px] flex justify-center"
|
options={{ language: 'fr', size: 'flexible' }}
|
||||||
|
onSuccess={onToken}
|
||||||
|
onExpire={() => onToken('')}
|
||||||
|
onError={() => onToken('')}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user