66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/faceai_config.php';
|
|
|
|
$config = faceai_config();
|
|
|
|
try {
|
|
$raceId = faceai_request_value('raceId');
|
|
$raceSlug = faceai_request_value('raceSlug');
|
|
$raceName = faceai_request_value('raceName', $raceSlug !== '' ? $raceSlug : $raceId);
|
|
$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',
|
|
'Mancano i parametri minimi richiesti per lanciare FaceAI.',
|
|
array(
|
|
'Parametri richiesti: raceId, returnUrl.',
|
|
'Il pulsante Face ID deve passare anche raceSlug e lang quando disponibili.'
|
|
),
|
|
400
|
|
);
|
|
}
|
|
|
|
$identity = faceai_resolve_identity($config);
|
|
if ($identity === null) {
|
|
faceai_redirect_with_error($returnUrl, 'Il servizio Face ID non e al momento disponibile. Riprova piu tardi.');
|
|
}
|
|
|
|
if (($identity['membershipStatus'] ?? 'inactive') !== 'active') {
|
|
faceai_redirect_with_error($returnUrl, 'Il tuo account non e abilitato all uso di Face ID.');
|
|
}
|
|
|
|
$payload = array(
|
|
'type' => 'handoff',
|
|
'user' => array(
|
|
'id' => $identity['id'],
|
|
'displayName' => $identity['displayName'],
|
|
'email' => $identity['email'],
|
|
'membershipStatus' => $identity['membershipStatus']
|
|
),
|
|
'race' => array(
|
|
'id' => $raceId,
|
|
'slug' => $raceSlug !== '' ? $raceSlug : $raceId,
|
|
'name' => $raceName !== '' ? $raceName : $raceId
|
|
),
|
|
'lang' => $lang,
|
|
'returnUrl' => $returnUrl,
|
|
'expiresAt' => ((int) round(microtime(true) * 1000)) + (5 * 60 * 1000)
|
|
);
|
|
|
|
$token = faceai_sign_payload($payload, $config['shared_secret']);
|
|
$targetUrl = faceai_build_url($config['frontend_url'] . '/auth/callback', array('token' => $token));
|
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
|
header('Pragma: no-cache');
|
|
header('Location: ' . $targetUrl, true, 302);
|
|
exit;
|
|
} catch (Throwable $error) {
|
|
faceai_redirect_with_error(isset($returnUrl) ? $returnUrl : '', 'Il servizio Face ID non e al momento disponibile. Riprova piu tardi.');
|
|
}
|