Compare commits
6 Commits
release-1.
...
release-1.
| Author | SHA1 | Date | |
|---|---|---|---|
| d56b91479f | |||
| 7c1e4cf3e2 | |||
| 3a5eed6b96 | |||
| e8080be405 | |||
| 82d3daf20f | |||
| 13584d2b0f |
12
Jenkinsfile
vendored
12
Jenkinsfile
vendored
@@ -83,12 +83,17 @@ pipeline {
|
|||||||
env.FRONTEND_API_URL = ''
|
env.FRONTEND_API_URL = ''
|
||||||
env.FRONTEND_GA_ID = ""
|
env.FRONTEND_GA_ID = ""
|
||||||
}
|
}
|
||||||
|
env.TURNSTILE_SITE_KEY = sh(
|
||||||
|
script: "grep '^TURNSTILE_SITE_KEY=' /opt/furious-ducks/secrets/tiptop-mail.env | cut -d= -f2-",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
echo "Branche : ${env.BRANCH_NAME}"
|
echo "Branche : ${env.BRANCH_NAME}"
|
||||||
echo "Tag Docker : ${env.IMAGE_TAG}"
|
echo "Tag Docker : ${env.IMAGE_TAG}"
|
||||||
echo "Environnement : ${env.DEPLOY_ENV}"
|
echo "Environnement : ${env.DEPLOY_ENV}"
|
||||||
echo "Déploiement activé : ${env.DEPLOY_ENABLED}"
|
echo "Déploiement activé : ${env.DEPLOY_ENABLED}"
|
||||||
echo "API frontend : ${env.FRONTEND_API_URL}"
|
echo "API frontend : ${env.FRONTEND_API_URL}"
|
||||||
|
echo "Turnstile : ${env.TURNSTILE_SITE_KEY ? '[SET]' : '[EMPTY]'}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,6 +334,13 @@ 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,19 +1,124 @@
|
|||||||
import { Turnstile } from '@marsidev/react-turnstile'
|
import { useEffect, useRef } from 'react'
|
||||||
import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha'
|
import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha'
|
||||||
|
|
||||||
// `ref` expose reset() : un jeton Turnstile n'est valable qu'une fois, il faut
|
const TURNSTILE_SCRIPT_ID = 'cf-turnstile-script'
|
||||||
// en redemander un après chaque envoi refusé.
|
const TURNSTILE_SCRIPT_URL =
|
||||||
export default function Captcha({ ref, onToken }) {
|
'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'
|
||||||
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 (
|
||||||
<Turnstile
|
<div
|
||||||
ref={ref}
|
ref={containerRef}
|
||||||
siteKey={TURNSTILE_SITE_KEY}
|
id="turnstile-captcha"
|
||||||
options={{ language: 'fr', size: 'flexible' }}
|
className="w-full min-h-[65px] flex justify-center"
|
||||||
onSuccess={onToken}
|
|
||||||
onExpire={() => onToken('')}
|
|
||||||
onError={() => onToken('')}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,8 +236,11 @@ export default function Admin() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSaveGameSettings} className="mt-4 pt-4 border-t border-gray-200 flex flex-wrap items-end gap-3">
|
<form
|
||||||
<div className="flex-1 min-w-[220px]">
|
onSubmit={handleSaveGameSettings}
|
||||||
|
className="mt-4 pt-4 border-t border-gray-200 flex flex-col sm:flex-row sm:items-end gap-3"
|
||||||
|
>
|
||||||
|
<div className="w-full sm:flex-1 sm:min-w-[220px]">
|
||||||
<label htmlFor="game-start" className="block text-xs font-medium text-gray-700 mb-1">
|
<label htmlFor="game-start" className="block text-xs font-medium text-gray-700 mb-1">
|
||||||
{stats.gameWindow.configured ? 'Corriger la date de début' : 'Date de début du jeu-concours'}
|
{stats.gameWindow.configured ? 'Corriger la date de début' : 'Date de début du jeu-concours'}
|
||||||
</label>
|
</label>
|
||||||
@@ -253,7 +256,7 @@ export default function Admin() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={settingsSaving || !startDateInput}
|
disabled={settingsSaving || !startDateInput}
|
||||||
className="bg-[#006B6B] hover:bg-[#005959] disabled:opacity-50 text-white font-semibold px-4 py-2 rounded-lg transition-colors text-xs sm:text-sm"
|
className="w-full sm:w-auto bg-[#006B6B] hover:bg-[#005959] disabled:opacity-50 text-white font-semibold px-4 py-2 rounded-lg transition-colors text-xs sm:text-sm whitespace-nowrap"
|
||||||
>
|
>
|
||||||
{settingsSaving ? 'Enregistrement…' : stats.gameWindow.configured ? 'Mettre à jour' : 'Lancer le jeu'}
|
{settingsSaving ? 'Enregistrement…' : stats.gameWindow.configured ? 'Mettre à jour' : 'Lancer le jeu'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user