Updated configurations for deployment
This commit is contained in:
parent
81a1ac85af
commit
7b30f17065
9 changed files with 396 additions and 214 deletions
|
|
@ -114,6 +114,79 @@ function getCurrentLangValue() {
|
|||
return $("html").attr("lang") || "it";
|
||||
}
|
||||
|
||||
function faceAiFeatureEnabled() {
|
||||
var config = window.faceAiConfig || {};
|
||||
var simulatorConfig = window.faceAiSimulator || {};
|
||||
var value = typeof config.enabled !== "undefined" ? config.enabled : simulatorConfig.enabled;
|
||||
|
||||
if (typeof value === "string") {
|
||||
value = value.toLowerCase();
|
||||
return value === "1" || value === "true" || value === "yes" || value === "on";
|
||||
}
|
||||
|
||||
return value === true;
|
||||
}
|
||||
|
||||
function faceAiEscapeHtml(value) {
|
||||
return String(value || "")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function getFaceAiErrorState() {
|
||||
if (typeof URLSearchParams === "undefined") {
|
||||
return null;
|
||||
}
|
||||
|
||||
var params = new URLSearchParams(window.location.search || "");
|
||||
if (params.get("faceaiError") !== "1") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
title: params.get("faceaiErrorTitle") || "Face ID non disponibile",
|
||||
message: params.get("faceaiErrorMessage") || "Il servizio Face ID non e al momento disponibile. Riprova piu tardi."
|
||||
};
|
||||
}
|
||||
|
||||
function clearFaceAiErrorState() {
|
||||
if (!window.history || !window.history.replaceState || typeof URL === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
var cleanUrl = new URL(window.location.href);
|
||||
cleanUrl.searchParams.delete("faceaiError");
|
||||
cleanUrl.searchParams.delete("faceaiErrorTitle");
|
||||
cleanUrl.searchParams.delete("faceaiErrorMessage");
|
||||
window.history.replaceState({}, document.title, cleanUrl.pathname + cleanUrl.search + cleanUrl.hash);
|
||||
}
|
||||
|
||||
function showFaceAiErrorModal(title, message) {
|
||||
var modal = $("#faceAiErrorModal");
|
||||
|
||||
if (!modal.length) {
|
||||
$("body").append('<div class="modal fade" id="faceAiErrorModal" tabindex="-1" role="dialog" aria-labelledby="faceAiErrorModalLabel" aria-hidden="true"><div class="modal-dialog modal-sm" role="document"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="faceAiErrorModalLabel"></h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-close"></i> </button></div><div class="modal-body text-center"><p id="faceAiErrorModalMessage" class="mb-0"></p></div></div></div></div>');
|
||||
modal = $("#faceAiErrorModal");
|
||||
}
|
||||
|
||||
$("#faceAiErrorModalLabel").html(faceAiEscapeHtml(title));
|
||||
$("#faceAiErrorModalMessage").html(faceAiEscapeHtml(message));
|
||||
modal.modal("show");
|
||||
}
|
||||
|
||||
function initFaceAiErrorModal() {
|
||||
var errorState = getFaceAiErrorState();
|
||||
if (!errorState) {
|
||||
return;
|
||||
}
|
||||
|
||||
showFaceAiErrorModal(errorState.title, errorState.message);
|
||||
clearFaceAiErrorState();
|
||||
}
|
||||
|
||||
function buildFaceAiLaunchUrl() {
|
||||
var raceId = $("#id_gara").val() || "";
|
||||
var raceSlug = $("#garaDesc").val() || "";
|
||||
|
|
@ -153,7 +226,7 @@ function launchFaceAi() {
|
|||
|
||||
function initFaceAiRaceSearchButton() {
|
||||
var select = $("#tipoPuntoFoto");
|
||||
if (!select.length || $("#faceaiLaunchButton").length) {
|
||||
if (!select.length || $("#faceaiLaunchButton").length || !faceAiFeatureEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -377,6 +450,7 @@ function goPage()
|
|||
|
||||
$(function() {
|
||||
initFaceAiRaceSearchButton();
|
||||
initFaceAiErrorModal();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,69 @@ function faceai_env($key, $default = null)
|
|||
return $value === false ? $default : $value;
|
||||
}
|
||||
|
||||
function faceai_env_flag($key, $default = false)
|
||||
{
|
||||
$value = strtolower(trim((string) faceai_env($key, $default ? '1' : '0')));
|
||||
return in_array($value, array('1', 'true', 'yes', 'on'), true);
|
||||
}
|
||||
|
||||
function faceai_request_host()
|
||||
{
|
||||
if (empty($_SERVER['HTTP_HOST'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return strtolower(trim((string) $_SERVER['HTTP_HOST']));
|
||||
}
|
||||
|
||||
function faceai_is_local_host($host)
|
||||
{
|
||||
$normalized = strtolower(trim((string) $host));
|
||||
if ($normalized === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$withoutPort = preg_replace('/:\d+$/', '', $normalized);
|
||||
return in_array($withoutPort, array('localhost', '127.0.0.1', '::1'), true);
|
||||
}
|
||||
|
||||
function faceai_request_targets_local_frontend()
|
||||
{
|
||||
if (faceai_is_local_host(faceai_request_host())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$returnUrl = faceai_request_value('returnUrl');
|
||||
if ($returnUrl === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$host = parse_url($returnUrl, PHP_URL_HOST);
|
||||
if (!is_string($host) || $host === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return faceai_is_local_host($host);
|
||||
}
|
||||
|
||||
function faceai_default_frontend_url()
|
||||
{
|
||||
if (faceai_request_targets_local_frontend()) {
|
||||
return 'http://localhost:3001';
|
||||
}
|
||||
|
||||
return 'https://ai.regalamiunsorriso.it';
|
||||
}
|
||||
|
||||
function faceai_default_backend_internal_url()
|
||||
{
|
||||
if (faceai_is_local_host(faceai_request_host())) {
|
||||
return 'http://localhost:3001';
|
||||
}
|
||||
|
||||
return 'https://ai.regalamiunsorriso.it';
|
||||
}
|
||||
|
||||
function faceai_config()
|
||||
{
|
||||
static $config = null;
|
||||
|
|
@ -15,10 +78,11 @@ function faceai_config()
|
|||
}
|
||||
|
||||
$config = array(
|
||||
'frontend_url' => rtrim(faceai_env('FACEAI_FRONTEND_URL', 'http://localhost:5173'), '/'),
|
||||
'backend_internal_url' => rtrim(faceai_env('FACEAI_BACKEND_INTERNAL_URL', 'http://localhost:3001'), '/'),
|
||||
'feature_enabled' => faceai_env_flag('FACEAI_FEATURE_ENABLED', false),
|
||||
'frontend_url' => rtrim(faceai_env('FACEAI_FRONTEND_URL', faceai_default_frontend_url()), '/'),
|
||||
'backend_internal_url' => rtrim(faceai_env('FACEAI_BACKEND_INTERNAL_URL', faceai_default_backend_internal_url()), '/'),
|
||||
'shared_secret' => (string) faceai_env('FACEAI_SHARED_SECRET', 'change-me'),
|
||||
'allow_dev_handoff' => faceai_env('FACEAI_ALLOW_DEV_HANDOFF', '1') === '1',
|
||||
'allow_dev_handoff' => faceai_env_flag('FACEAI_ALLOW_DEV_HANDOFF', true),
|
||||
'identity_cookie' => (string) faceai_env('FACEAI_IDENTITY_COOKIE', 'rus_faceai_identity'),
|
||||
'return_forward_url' => rtrim((string) faceai_env('FACEAI_RETURN_FORWARD_URL', ''), '/')
|
||||
);
|
||||
|
|
@ -80,6 +144,22 @@ function faceai_build_url($baseUrl, array $params)
|
|||
return $baseUrl . (strpos($baseUrl, '?') === false ? '?' : '&') . http_build_query($params);
|
||||
}
|
||||
|
||||
function faceai_redirect_with_error($returnUrl, $message, $title = 'Face ID non disponibile')
|
||||
{
|
||||
if (is_string($returnUrl) && trim($returnUrl) !== '') {
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Pragma: no-cache');
|
||||
header('Location: ' . faceai_build_url($returnUrl, array(
|
||||
'faceaiError' => '1',
|
||||
'faceaiErrorTitle' => $title,
|
||||
'faceaiErrorMessage' => $message
|
||||
)), true, 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
faceai_render_message_page($title, $message, array(), 503);
|
||||
}
|
||||
|
||||
function faceai_request_value($key, $default = '')
|
||||
{
|
||||
if (!isset($_GET[$key])) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ try {
|
|||
$lang = faceai_request_value('lang', 'it');
|
||||
$returnUrl = faceai_request_value('returnUrl');
|
||||
|
||||
if (empty($config['feature_enabled'])) {
|
||||
faceai_redirect_with_error($returnUrl, 'La ricerca Face ID non e ancora disponibile.');
|
||||
}
|
||||
|
||||
if ($raceId === '' || $returnUrl === '') {
|
||||
faceai_render_message_page(
|
||||
'FaceAI handoff non disponibile',
|
||||
|
|
@ -25,25 +29,11 @@ try {
|
|||
|
||||
$identity = faceai_resolve_identity($config);
|
||||
if ($identity === null) {
|
||||
faceai_render_message_page(
|
||||
'FaceAI handoff in attesa del bridge legacy',
|
||||
'Questo endpoint PHP non puo leggere la sessione Java esistente. Per funzionare in produzione deve ricevere una identita firmata dal layer legacy o dal reverse proxy.',
|
||||
array(
|
||||
'Opzione consigliata: cookie firmato ' . $config['identity_cookie'] . ' con payload type=legacy-identity.',
|
||||
'Per test locale e possibile passare devUserId, devDisplayName, devEmail e devMembershipStatus se FACEAI_ALLOW_DEV_HANDOFF=1.',
|
||||
'Esempio locale: faceai_handoff.php?raceId=101&raceSlug=mezza-di-firenze&lang=it&returnUrl=http%3A%2F%2Flocalhost%2Fold&devUserId=1&devDisplayName=Mario%20Rossi&devEmail=mario%40example.test&devMembershipStatus=active'
|
||||
),
|
||||
501
|
||||
);
|
||||
faceai_redirect_with_error($returnUrl, 'Il servizio Face ID non e al momento disponibile. Riprova piu tardi.');
|
||||
}
|
||||
|
||||
if (($identity['membershipStatus'] ?? 'inactive') !== 'active') {
|
||||
faceai_render_message_page(
|
||||
'FaceAI non disponibile',
|
||||
'L utente corrente non risulta abilitato all uso di FaceAI in base allo stato di membership.',
|
||||
array('Stato attuale: ' . ($identity['membershipStatus'] ?? 'unknown')),
|
||||
403
|
||||
);
|
||||
faceai_redirect_with_error($returnUrl, 'Il tuo account non e abilitato all uso di Face ID.');
|
||||
}
|
||||
|
||||
$payload = array(
|
||||
|
|
@ -72,5 +62,5 @@ try {
|
|||
header('Location: ' . $targetUrl, true, 302);
|
||||
exit;
|
||||
} catch (Throwable $error) {
|
||||
faceai_render_message_page('Errore handoff FaceAI', $error->getMessage(), array(), 500);
|
||||
faceai_redirect_with_error(isset($returnUrl) ? $returnUrl : '', 'Il servizio Face ID non e al momento disponibile. Riprova piu tardi.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ function faceai_sim_render_page(array $options)
|
|||
<?php if ($showSimulatorBootstrap): ?>
|
||||
<script>
|
||||
window.faceAiSimulator = {
|
||||
enabled: true,
|
||||
handoffUrl: 'faceai_handoff.php',
|
||||
returnUrl: <?php echo json_encode($returnUrl); ?>,
|
||||
devUserId: '1',
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@
|
|||
</jsp:useBean>
|
||||
<jsp:useBean id="user" class="it.acxent.pg.Users" type="it.acxent.pg.Users" scope="request" >
|
||||
</jsp:useBean>
|
||||
<%
|
||||
String faceAiFeatureEnabledValue = System.getenv("FACEAI_FEATURE_ENABLED");
|
||||
if (faceAiFeatureEnabledValue == null) {
|
||||
faceAiFeatureEnabledValue = System.getProperty("FACEAI_FEATURE_ENABLED", "0");
|
||||
}
|
||||
boolean faceAiFeatureEnabled = "1".equals(faceAiFeatureEnabledValue) || "true".equalsIgnoreCase(faceAiFeatureEnabledValue) || "yes".equalsIgnoreCase(faceAiFeatureEnabledValue) || "on".equalsIgnoreCase(faceAiFeatureEnabledValue);
|
||||
%>
|
||||
<!-- InstanceEndEditable -->
|
||||
<!-- InstanceBeginEditable name="doctitle" -->
|
||||
<title><acx:lang>Regalami Un Sorriso ETS - Gare</acx:lang><%=CR.getTipoGara().getDescrizione()%></title>
|
||||
|
|
@ -313,6 +320,11 @@
|
|||
<!-- Footer -->
|
||||
<jsp:include page="_inc_footer.jsp" flush="true" />
|
||||
|
||||
<script>
|
||||
window.faceAiConfig = window.faceAiConfig || {};
|
||||
window.faceAiConfig.enabled = <%= faceAiFeatureEnabled ? "true" : "false" %>;
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$('#datepicker-sport').datepicker({
|
||||
language: "it"
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@
|
|||
</jsp:useBean>
|
||||
<jsp:useBean id="user" class="it.acxent.pg.Users" type="it.acxent.pg.Users" scope="request" >
|
||||
</jsp:useBean>
|
||||
<%
|
||||
String faceAiFeatureEnabledValue = System.getenv("FACEAI_FEATURE_ENABLED");
|
||||
if (faceAiFeatureEnabledValue == null) {
|
||||
faceAiFeatureEnabledValue = System.getProperty("FACEAI_FEATURE_ENABLED", "0");
|
||||
}
|
||||
boolean faceAiFeatureEnabled = "1".equals(faceAiFeatureEnabledValue) || "true".equalsIgnoreCase(faceAiFeatureEnabledValue) || "yes".equalsIgnoreCase(faceAiFeatureEnabledValue) || "on".equalsIgnoreCase(faceAiFeatureEnabledValue);
|
||||
%>
|
||||
<!-- InstanceEndEditable -->
|
||||
<!-- InstanceBeginEditable name="doctitle" -->
|
||||
<title><acx:lang>Regalami Un Sorriso ETS - Gare</acx:lang><%=CR.getTipoGara().getDescrizione()%></title>
|
||||
|
|
@ -313,6 +320,11 @@
|
|||
<!-- Footer -->
|
||||
<jsp:include page="_inc_footer.jsp" flush="true" />
|
||||
|
||||
<script>
|
||||
window.faceAiConfig = window.faceAiConfig || {};
|
||||
window.faceAiConfig.enabled = <%= faceAiFeatureEnabled ? "true" : "false" %>;
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$('#datepicker-sport').datepicker({
|
||||
language: "it"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue